VirtualBox

Changeset 36887 in vbox for trunk/src


Ignore:
Timestamp:
Apr 29, 2011 10:04:52 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
71465
Message:

GuestCtrl: Added support for getting separated stdout/stderr output.

Location:
trunk/src/VBox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlExec.cpp

    r36756 r36887  
    191191
    192192/**
    193  * Handle pending output data or error on standard out, standard error or the
    194  * test pipe.
    195  *
    196  * @returns IPRT status code from client send.
    197  * @param   pThread             The thread specific data.
     193 * Handle pending output data/error on standard out or standard error.
     194 *
     195 * @return  IPRT status code.
    198196 * @param   hPollSet            The polling set.
    199197 * @param   fPollEvt            The event mask returned by RTPollNoResume.
    200  * @param   phPipeR             The pipe handle.
    201  * @param   pu32Crc             The current CRC-32 of the stream. (In/Out)
    202  * @param   uHandleId           The handle ID.
    203  *
    204  * @todo    Put the last 4 parameters into a struct!
     198 * @param   phPipeR             The pipe to be read from.
     199 * @param   uHandleId           Handle ID of the pipe to be read from.
     200 * @param   pBuf                Pointer to pipe buffer to store the read data into.
    205201 */
    206202static int VBoxServiceControlExecProcHandleOutputEvent(RTPOLLSET hPollSet, uint32_t fPollEvt, PRTPIPE phPipeR,
    207                                                        uint32_t uHandleId, PVBOXSERVICECTRLEXECPIPEBUF pStdOutBuf)
    208 {
     203                                                       uint32_t uHandleId, PVBOXSERVICECTRLEXECPIPEBUF pBuf)
     204{
     205    AssertPtrReturn(phPipeR, VERR_INVALID_POINTER);
     206    AssertPtrReturn(pBuf, VERR_INVALID_POINTER);
     207
    209208#ifdef DEBUG
    210     VBoxServiceVerbose(4, "ControlExec: HandleOutputEvent: fPollEvt=%#x\n", fPollEvt);
     209    VBoxServiceVerbose(4, "ControlExec: HandleOutputEvent: fPollEvt=%#x, uHandle=%u\n",
     210                       fPollEvt, uHandleId);
    211211#endif
    212212
     
    222222    {
    223223        uint32_t cbWritten;
    224         rc = VBoxServicePipeBufWriteToBuf(pStdOutBuf, abBuf,
     224        rc = VBoxServicePipeBufWriteToBuf(pBuf, abBuf,
    225225                                          cbRead, false /* Pending close */, &cbWritten);
    226226        if (RT_SUCCESS(rc))
     
    376376                case VBOXSERVICECTRLPIPEID_STDERR:
    377377                    rc = VBoxServiceControlExecProcHandleOutputEvent(hPollSet, fPollEvt, phStdErrR,
    378                                                                      VBOXSERVICECTRLPIPEID_STDERR, &pData->stdOut);
     378                                                                     VBOXSERVICECTRLPIPEID_STDERR, &pData->stdErr);
    379379                    break;
    380380
     
    13481348                 *       on the host never will get completed! */
    13491349                /* cbRead now contains actual size. */
    1350                 rc = VbglR3GuestCtrlExecSendOut(u32ClientId, uContextID, uPID, uHandleID, 0 /* Flags */,
     1350                rc = VbglR3GuestCtrlExecSendOut(u32ClientId, uContextID, uPID, uHandleID, uFlags,
    13511351                                                pBuf, cbRead);
    13521352            }
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlExecThread.cpp

    r36749 r36887  
    2727#include <iprt/semaphore.h>
    2828#include <iprt/string.h>
     29
     30#include <VBox/HostServices/GuestControlSvc.h>
    2931
    3032#include "VBoxServicePipeBuf.h"
     
    285287            switch (uHandleId)
    286288            {
    287                 case 2: /* StdErr */
     289                case OUTPUT_HANDLE_ID_STDERR: /* StdErr */
    288290                    pPipeBuf = &pData->stdErr;
    289291                    break;
    290292
    291                 case 0: /* StdOut */
     293                case OUTPUT_HANDLE_ID_STDOUT: /* StdOut */
    292294                default:
    293295                    pPipeBuf = &pData->stdOut;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp

    r36784 r36887  
    408408
    409409    Utf8Str                 Utf8Cmd;
    410     uint32_t                fFlags = 0;
     410    uint32_t                fExecFlags = ExecuteProcessFlag_None;
     411    uint32_t                fOutputFlags = ProcessOutputFlag_None;
    411412    com::SafeArray<IN_BSTR> args;
    412413    com::SafeArray<IN_BSTR> env;
     
    418419    bool                    fWaitForExit    = false;
    419420    bool                    fWaitForStdOut  = false;
    420     bool                    fWaitForStdErr  = false;
    421421    bool                    fVerbose        = false;
    422422
     
    450450
    451451            case GETOPTDEF_EXEC_IGNOREORPHANEDPROCESSES:
    452                 fFlags |= ExecuteProcessFlag_IgnoreOrphanedProcesses;
     452                fExecFlags |= ExecuteProcessFlag_IgnoreOrphanedProcesses;
    453453                break;
    454454
     
    491491
    492492            case GETOPTDEF_EXEC_WAITFORSTDERR:
    493                 fWaitForExit = true;
    494                 fWaitForStdErr = true;
     493                fWaitForExit = (fOutputFlags |= ProcessOutputFlag_StdErr);
    495494                break;
    496495
     
    538537    ULONG uPID = 0;
    539538    rc = guest->ExecuteProcess(Bstr(Utf8Cmd).raw(),
    540                                fFlags,
     539                               fExecFlags,
    541540                               ComSafeArrayAsInParam(args),
    542541                               ComSafeArrayAsInParam(env),
     
    590589             * Some data left to output?
    591590             */
    592             if (   fWaitForStdOut
    593                 || fWaitForStdErr)
     591            if (fOutputFlags || fWaitForStdOut)
    594592            {
    595593                /** @todo r=bird: The timeout argument is bogus in several
     
    615613                 *     unsigned 64-bit and never return 0.
    616614                 */
    617                 /** @todo r=bird: We must separate stderr and stdout
    618                  *        output, seems bunched together here which
    619                  *        won't do the trick for unix BOFHs. */
    620                 rc = guest->GetProcessOutput(uPID, 0 /* aFlags */,
     615                rc = guest->GetProcessOutput(uPID, fOutputFlags,
    621616                                             RT_MAX(0, cMsTimeout - (RTTimeMilliTS() - u64StartMS)) /* Timeout in ms */,
    622617                                             _64K, ComSafeArrayAsOutParam(aOutputData));
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r36721 r36887  
    81448144
    81458145  <enum
     8146    name="ProcessOutputFlag"
     8147    uuid="9979e85a-52bb-40b7-870c-57115e27e0f1"
     8148    >
     8149    <desc>
     8150      Guest process output flags for specifying which
     8151      type of output to retrieve.
     8152    </desc>
     8153
     8154    <const name="None"                     value="0">
     8155      <desc>No flags set. Get output from stdout.</desc>
     8156    </const>
     8157
     8158    <const name="StdErr"                   value="1">
     8159      <desc>Get output from stderr.</desc>
     8160    </const>
     8161  </enum>
     8162
     8163  <enum
    81468164    name="CopyFileFlag"
    81478165    uuid="23f79fdf-738a-493d-b80b-42d607c9b916"
     
    84278445      <param name="flags" type="unsigned long" dir="in">
    84288446        <desc>
    8429           Flags describing which output to retrieve.
     8447          <link to="ProcessOutputFlag"/> flags.
    84308448        </desc>
    84318449      </param>
  • trunk/src/VBox/Main/src-client/GuestCtrlImpl.cpp

    r36755 r36887  
    20312031    if (aSize < 0)
    20322032        return setError(E_INVALIDARG, tr("The size argument (%lld) is negative"), aSize);
    2033     if (aFlags != 0) /* Flags are not supported at the moment. */
    2034         return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), aFlags);
     2033    if (aFlags)
     2034    {
     2035        if (!(aFlags & ProcessOutputFlag_StdErr))
     2036        {
     2037            return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), aFlags);
     2038        }
     2039    }
    20352040
    20362041    AutoCaller autoCaller(this);
     
    20602065        if (aTimeoutMS == 0)
    20612066            aTimeoutMS = UINT32_MAX;
     2067        /* Set handle ID. */
     2068        uint32_t uHandleID = OUTPUT_HANDLE_ID_STDOUT; /* Default */
     2069        if (aFlags & ProcessOutputFlag_StdErr)
     2070            uHandleID = OUTPUT_HANDLE_ID_STDERR;
    20622071
    20632072        /* Search for existing PID. */
     
    20732082        Assert(uContextID > 0);
    20742083
    2075         com::SafeArray<BYTE> outputData((size_t)aSize);
    2076 
    20772084        VBOXHGCMSVCPARM paParms[5];
    20782085        int i = 0;
    20792086        paParms[i++].setUInt32(uContextID);
    20802087        paParms[i++].setUInt32(aPID);
    2081         paParms[i++].setUInt32(aFlags); /** @todo Should represent stdout and/or stderr. */
    2082 
     2088        paParms[i++].setUInt32(uHandleID);
     2089        paParms[i++].setUInt32(0 /* Flags, none set yet */);
     2090
     2091        com::SafeArray<BYTE> outputData((size_t)aSize);
    20832092        int vrc = VINF_SUCCESS;
    20842093
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette