GuestCtrlImpl.cpp revision d61062de73b8b84dafaec241400fb590bdf4a74a
/* $Id$ */
/** @file
* VirtualBox COM class implementation: Guest
*/
/*
* Copyright (C) 2006-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "GuestImpl.h"
#include "GuestCtrlImplPrivate.h"
#include "Global.h"
#include "ConsoleImpl.h"
#include "ProgressImpl.h"
#include "VMMDev.h"
#include "AutoCaller.h"
#include "Logging.h"
#ifdef VBOX_WITH_GUEST_CONTROL
#endif
#include <memory>
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
#ifdef VBOX_WITH_GUEST_CONTROL
/**
* Appends environment variables to the environment block.
*
* Each var=value pair is separated by the null character ('\\0'). The whole
* block will be stored in one blob and disassembled on the guest side later to
* fit into the HGCM param structure.
*
* @returns VBox status code.
*
* @param pszEnvVar The environment variable=value to append to the
* environment block.
* @param ppvList This is actually a pointer to a char pointer
* variable which keeps track of the environment block
* that we're constructing.
* @param pcbList Pointer to the variable holding the current size of
* the environment block. (List is a misnomer, go
* ahead a be confused.)
* @param pcEnvVars Pointer to the variable holding count of variables
* stored in the environment block.
*/
int Guest::prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnvVars)
{
int rc = VINF_SUCCESS;
if (*ppvList)
{
rc = VERR_NO_MEMORY;
else
{
}
}
else
{
char *pszTmp;
{
/* Reset counters. */
*pcEnvVars = 0;
*pcbList = 0;
}
}
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Adds a callback with a user provided data block and an optional progress object
* to the callback map. A callback is identified by a unique context ID which is used
* to identify a callback from the guest side.
*
* @return IPRT status code.
* @param pCallback
* @param puContextID
*/
{
/* puContextID is optional. */
int rc = VERR_NOT_FOUND;
/* Create a new context ID and assign it. */
uint32_t uNewContextID = 0;
for (;;)
{
/* Create a new context ID ... */
if (uNewContextID == UINT32_MAX)
/* Is the context ID already used? Try next ID ... */
if (!callbackExists(uNewContextID))
{
/* Callback with context ID was not found. This means
* we can use this context ID for our new callback we want
* to add below. */
rc = VINF_SUCCESS;
break;
}
if (++uTries == UINT32_MAX)
break; /* Don't try too hard. */
}
if (RT_SUCCESS(rc))
{
/* Add callback with new context ID to our callback map. */
/* Report back new context ID. */
if (puContextID)
}
return rc;
}
/**
* Destroys the formerly allocated callback data. The callback then
* needs to get removed from the callback map via callbackRemove().
* Does not do locking!
*
* @param uContextID
*/
{
{
{
}
}
}
/**
* Removes a callback from the callback map.
* Does not do locking!
*
* @param uContextID
*/
{
}
/**
* Checks whether a callback with the given context ID
* exists or not.
* Does not do locking!
*
* @return bool True, if callback exists, false if not.
* @param uContextID Context ID to check.
*/
{
AssertReturn(uContextID, false);
}
{
if (pvData)
{
}
}
{
/* pEnmType is optional. */
/* ppvData is optional. */
/* pcbData is optional. */
return VERR_NOT_FOUND;
if (pEnmType)
if ( ppvData
{
}
if (pcbData)
return VINF_SUCCESS;
}
/* Does not do locking! Caller has to take care of it because the caller needs to
* modify the data ...*/
{
/* pcbData is optional. */
{
if (pcbData)
}
return NULL;
}
{
/* Everything else is optional. */
int vrc = VINF_SUCCESS;
switch (enmType)
{
{
PCALLBACKDATAEXECSTATUS pData = (PCALLBACKDATAEXECSTATUS)RTMemAlloc(sizeof(CALLBACKDATAEXECSTATUS));
break;
}
{
break;
}
{
PCALLBACKDATAEXECINSTATUS pData = (PCALLBACKDATAEXECINSTATUS)RTMemAlloc(sizeof(CALLBACKDATAEXECINSTATUS));
break;
}
default:
break;
}
if (RT_SUCCESS(vrc))
{
}
return vrc;
}
{
AssertReturn(uContextID, true);
{
}
if (pProgress)
{
&& !fCanceled)
{
return false;
}
}
return true; /* No progress / error means canceled. */
}
{
AssertReturn(uContextID, true);
{
}
if (pProgress)
{
&& fCompleted)
{
return true;
}
}
return false;
}
{
{
}
if (pProgress)
{
return VERR_CANCELLED;
return VINF_SUCCESS;
}
return VERR_NOT_FOUND;
}
/**
* Notifies a specified callback about its final status.
*
* @return IPRT status code.
* @param uContextID
* @param iRC
* @param pszMessage
*/
{
if (RT_FAILURE(iRC))
LogFlowFunc(("Checking whether callback (CID=%u) needs notification iRC=%Rrc, pszMsg=%s\n",
{
}
#if 0
&& fCanceled)
{
/* If progress already canceled do nothing here. */
return VINF_SUCCESS;
}
#endif
if (pProgress)
{
/*
* Assume we didn't complete to make sure we clean up even if the
* following call fails.
*/
&& !fCompleted)
{
LogFlowFunc(("Notifying callback with CID=%u, iRC=%Rrc, pszMsg=%s\n",
/*
* To get waitForCompletion completed (unblocked) we have to notify it if necessary (only
* cancel won't work!). This could happen if the client thread (e.g. VBoxService, thread of a spawned process)
* is disconnecting without having the chance to sending a status message before, so we
* progress object to become signalled.
*/
if (RT_SUCCESS(iRC))
{
}
else
{
}
LogFlowFunc(("Notified callback with CID=%u returned %Rhrc (0x%x)\n",
}
else
/*
* Do *not* NULL pProgress here, because waiting function like executeProcess()
* will still rely on this object for checking whether they have to give up!
*/
}
/* If pProgress is not found (anymore) that's fine.
* Might be destroyed already. */
return S_OK;
}
/**
* TODO
*
* @return IPRT status code.
* @param uPID
* @param iRC
* @param pszMessage
*/
{
int vrc = VINF_SUCCESS;
{
{
break;
/* When waiting for process output while the process is destroyed,
* make sure we also destroy the actual waiting operation (internal progress object)
* in order to not block the caller. */
{
break;
}
/* When waiting for injecting process input while the process is destroyed,
* make sure we also destroy the actual waiting operation (internal progress object)
* in order to not block the caller. */
{
break;
}
default:
AssertMsgFailed(("Unknown callback type %d, iRC=%d, message=%s\n",
break;
}
if (RT_FAILURE(vrc))
break;
}
return vrc;
}
{
}
/**
* Waits for a callback (using its context ID) to complete.
*
* @return IPRT status code.
* @param uContextID Context ID to wait for.
* Specifying a stage is only needed if there's a multi operation progress
* object to wait for.
* @param lTimeout Timeout (in ms) to wait for.
*/
{
/*
* Wait for the HGCM low level callback until the process
* has been started (or something went wrong). This is necessary to
* get the PID.
*/
int vrc = VINF_SUCCESS;
{
else
}
if (RT_SUCCESS(vrc))
{
LogFlowFunc(("Waiting for callback completion (CID=%u, Stage=%RI32, timeout=%RI32ms) ...\n",
if (lStage < 0)
else
{
if (!callbackIsComplete(uContextID))
}
else
vrc = VERR_TIMEOUT;
}
LogFlowFunc(("Callback (CID=%u) completed with rc=%Rrc\n",
uContextID, vrc));
return vrc;
}
/**
* Static callback function for receiving updates on guest control commands
* from the guest. Acts as a dispatcher for the actual class instance.
*
* @returns VBox status code.
*
* @todo
*
*/
void *pvParms,
{
using namespace guestControl;
/*
* No locking, as this is purely a notification which does not make any
* changes to the object state.
*/
#ifdef DEBUG_andy
LogFlowFunc(("pvExtension=%p, u32Function=%d, pvParms=%p, cbParms=%d\n",
#endif
int rc = VINF_SUCCESS;
switch (u32Function)
{
case GUEST_DISCONNECTED:
{
//LogFlowFunc(("GUEST_DISCONNECTED\n"));
PCALLBACKDATACLIENTDISCONNECTED pCBData = reinterpret_cast<PCALLBACKDATACLIENTDISCONNECTED>(pvParms);
AssertReturn(CALLBACKDATAMAGIC_CLIENT_DISCONNECTED == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
break;
}
case GUEST_EXEC_SEND_STATUS:
{
//LogFlowFunc(("GUEST_EXEC_SEND_STATUS\n"));
break;
}
case GUEST_EXEC_SEND_OUTPUT:
{
//LogFlowFunc(("GUEST_EXEC_SEND_OUTPUT\n"));
break;
}
{
//LogFlowFunc(("GUEST_EXEC_SEND_INPUT_STATUS\n"));
break;
}
default:
break;
}
return rc;
}
/* Function for handling the execution start/termination notification. */
/* Callback can be called several times. */
{
/* Scope write locks as much as possible. */
{
LogFlowFunc(("Execution status (CID=%u, pData=0x%p)\n",
uContextID, pData));
if (pCallbackData)
{
/** @todo Copy void* buffer contents? */
}
/* If pCallbackData is NULL this might be an old request for which no user data
* might exist anymore. */
}
/* Was progress canceled before? */
if (!fCanceled)
{
/* Handle process map. This needs to be done first in order to have a valid
* map in case some callback gets notified a bit below. */
/* Note: PIDs never get removed here in case the guest process signalled its
* end; instead the next call of GetProcessStatus() will remove the PID
* from the process map after we got the process' final (exit) status.
* See waitpid() for an example. */
{
{
/* Just reach through flags. */
case PROC_STS_TES:
case PROC_STS_TOK:
break;
/* Interprete u32Flags as the guest process' exit code. */
default:
break;
}
}
/* Do progress handling. */
{
case PROC_STS_STARTED:
break;
case PROC_STS_TEN: /* Terminated normally. */
break;
case PROC_STS_TEA: /* Terminated abnormally. */
LogRel(("Guest process (PID %u) terminated abnormally with exit code = %u\n",
break;
case PROC_STS_TES: /* Terminated through signal. */
LogRel(("Guest process (PID %u) terminated through signal with exit code = %u\n",
break;
case PROC_STS_TOK:
LogRel(("Guest process (PID %u) timed out and was killed\n", pData->u32PID)); /** @todo Add process name */
break;
case PROC_STS_TOA:
LogRel(("Guest process (PID %u) timed out and could not be killed\n", pData->u32PID)); /** @todo Add process name */
break;
case PROC_STS_DWN:
LogRel(("Guest process (PID %u) killed because system is shutting down\n", pData->u32PID)); /** @todo Add process name */
/*
* If u32Flags has ExecuteProcessFlag_IgnoreOrphanedProcesses set, we don't report an error to
* our progress object. This is helpful for waiters which rely on the success of our progress object
* even if the executed process was killed because the system/VBoxService is shutting down.
*
* In this case u32Flags contains the actual execution flags reached in via Guest::ExecuteProcess().
*/
{
}
else
{
}
break;
case PROC_STS_ERROR:
{
LogRel(("Guest process (PID %u) could not be started because of rc=%Rrc\n",
}
else
{
{
case VERR_MAX_PROCS_REACHED:
LogRel(("Guest process could not be started because maximum number of parallel guest processes has been reached\n"));
break;
default:
LogRel(("Guest process could not be started because of rc=%Rrc\n",
}
}
break;
default:
break;
}
}
else
{
}
/* Do we need to handle the callback error? */
if (RT_FAILURE(rcCallback))
{
/* Notify all callbacks which are still waiting on something
* which is related to the current PID. */
{
if (RT_FAILURE(rc2))
{
LogFlowFunc(("Failed to notify other callbacks for PID=%u\n",
if (RT_SUCCESS(vrc))
}
}
/* Let the caller know what went wrong ... */
if (RT_FAILURE(rc2))
{
LogFlowFunc(("Failed to notify callback CID=%u for PID=%u\n",
if (RT_SUCCESS(vrc))
}
LogFlowFunc(("Process (CID=%u, status=%u) reported: %s\n",
}
LogFlowFunc(("Returned with rc=%Rrc, rcCallback=%Rrc\n",
vrc, rcCallback));
return vrc;
}
/* Function for handling the execution output notification. */
{
/* Scope write locks as much as possible. */
{
LogFlowFunc(("Output status (CID=%u, pData=0x%p)\n",
uContextID, pData));
if (pCallbackData)
{
/* Make sure we really got something! */
{
/* Allocate data buffer and copy it */
}
else /* Nothing received ... */
{
pCallbackData->cbData = 0;
}
}
/* If pCallbackData is NULL this might be an old request for which no user data
* might exist anymore. */
}
int vrc;
{
}
else
return vrc;
}
/* Function for handling the execution input status notification. */
{
/* Scope write locks as much as possible. */
{
LogFlowFunc(("Input status (CID=%u, pData=0x%p)\n",
uContextID, pData));
if (pCallbackData)
{
/* Save bytes processed. */
}
/* If pCallbackData is NULL this might be an old request for which no user data
* might exist anymore. */
}
return callbackNotifyComplete(uContextID);
}
{
/* u32Function is 0. */
}
/**
* Gets guest process information. Removes the process from the map
* after the process was marked as exited/terminated.
*
* @return IPRT status code.
* @param u32PID PID of process to get status for.
* @param pProcess Where to store the process information.
* @param fRemove Flag indicating whether to remove the
* process from the map when process marked a
* exited/terminated.
*/
bool fRemove)
{
{
if (pProcess)
{
}
/* If the is marked as stopped/terminated
* remove it from the map. */
if ( fRemove
{
}
return VINF_SUCCESS;
}
return VERR_NOT_FOUND;
}
int Guest::processSetStatus(uint32_t u32PID, ExecuteProcessStatus_T enmStatus, uint32_t uExitCode, uint32_t uFlags)
{
{
}
else
{
}
return VINF_SUCCESS;
}
{
if (rc == VERR_NOT_FOUND)
tr("VMM device is not available (is the VM running?)"));
else if (rc == VERR_CANCELLED)
tr("Process execution has been canceled"));
else if (rc == VERR_TIMEOUT)
tr("The guest did not respond within time"));
else
return hRC;
}
{
if (rc == VERR_INVALID_VM_HANDLE)
tr("VMM device is not available (is the VM running?)"));
else if (rc == VERR_NOT_FOUND)
tr("The guest execution service is not ready (yet)"));
else if (rc == VERR_HGCM_SERVICE_NOT_FOUND)
tr("The guest execution service is not available"));
else /* HGCM call went wrong. */
return hRC;
}
#endif /* VBOX_WITH_GUEST_CONTROL */
{
/** @todo r=bird: Eventually we should clean up all the timeout parameters
* in the API and have the same way of specifying infinite waits! */
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
/* Do not allow anonymous executions (with system rights). */
LogRel(("Executing guest process \"%s\" as user \"%s\" ...\n",
#endif
}
#ifdef VBOX_WITH_GUEST_CONTROL
/**
* Executes and waits for an internal tool (that is, a tool which is integrated into
* VBoxService, beginning with "vbox_" (e.g. "vbox_ls")) to finish its operation.
*
* @return HRESULT
* @param aTool Name of tool to execute.
* @param aDescription Friendly description of the operation.
* @param aFlags Execution flags.
* @param aUsername Username to execute tool under.
* @param aPassword The user's password.
* @param uFlagsToAdd ExecuteProcessFlag flags to add to the execution operation.
* @param aProgress Pointer which receives the tool's progress object. Optional.
* @param aPID Pointer which receives the tool's PID. Optional.
*/
{
if (uFlagsToAdd)
uFlags |= uFlagsToAdd;
bool fWaitForOutput = false;
if ( ( (uFlags & ExecuteProcessFlag_WaitForStdOut)
&& pObjStdOut)
|| ( (uFlags & ExecuteProcessFlag_WaitForStdErr)
&& pObjStdErr))
{
fWaitForOutput = true;
}
0 /* No timeout. */,
&& fWaitForOutput)
{
&& !fCompleted)
{
if (fCanceled)
{
break;
}
if ( (uFlags & ExecuteProcessFlag_WaitForStdOut)
&& pObjStdOut)
{
}
if ( (uFlags & ExecuteProcessFlag_WaitForStdErr)
&& pObjStdErr)
{
}
break;
}
}
{
if (aProgress)
{
/* Return the progress to the caller. */
}
if (aPID)
}
return rc;
}
{
/* Did we get some status? */
switch (pExecStatus->u32Status)
{
case PROC_STS_STARTED:
/* Process is (still) running; get PID. */
break;
/* In any other case the process either already
* terminated or something else went wrong, so no PID ... */
case PROC_STS_TEN: /* Terminated normally. */
case PROC_STS_TEA: /* Terminated abnormally. */
case PROC_STS_TES: /* Terminated through signal. */
case PROC_STS_TOK:
case PROC_STS_TOA:
case PROC_STS_DWN:
/*
* Process (already) ended, but we want to get the
* PID anyway to retrieve the output in a later call.
*/
break;
case PROC_STS_ERROR:
{
else if (vrc == VERR_PATH_NOT_FOUND)
else if (vrc == VERR_BAD_EXE_FORMAT)
else if (vrc == VERR_AUTHENTICATION_FAILURE)
else if (vrc == VERR_TIMEOUT)
else if (vrc == VERR_CANCELLED)
tr("The execution operation was canceled"));
else if (vrc == VERR_PERMISSION_DENIED)
else if (vrc == VERR_MAX_PROCS_REACHED)
tr("Concurrent guest process limit is reached"));
else
{
else
}
}
break;
case PROC_STS_UNDEFINED: /* . */
tr("The operation did not complete within time"));
break;
default:
AssertReleaseMsgFailed(("Process (PID %u) reported back an undefined state!\n",
pExecStatus->u32PID));
rc = E_UNEXPECTED;
break;
}
return rc;
}
/**
* TODO
*
* @return HRESULT
* @param aObjName
* @param pStreamBlock
* @param pObjInfo
* @param enmAddAttribs
*/
{
if (RT_SUCCESS(rc))
/** @todo Add more stuff! */
return rc;
}
/**
* Tries to drain the guest's output and fill it into
* a guest process stream object for later usage.
*
* @todo What's about specifying stderr?
* @return IPRT status code.
* @param aPID PID of process to get the output from.
* @param aFlags Which stream to drain (stdout or stderr).
* @param stream Reference to guest process stream to fill.
*/
{
int rc = VINF_SUCCESS;
for (;;)
{
0 /* Infinite timeout */,
{
{
break;
}
continue; /* Try one more time. */
}
{
if (rc == VERR_NOT_FOUND)
rc = VINF_SUCCESS;
break;
}
}
return rc;
}
/**
* Tries to retrieve the next stream block of a given stream and
* drains the process output only as much as needed to get this next
* stream block.
*
* @return IPRT status code.
* @param ulPID
* @param ulFlags
* @param stream
* @param streamBlock
*/
{
LogFlowFunc(("Getting next stream block of PID=%u, Flags=%u; cbStrmSize=%u, cbStrmOff=%u\n",
int rc;
bool fDrainStream = true;
do
{
LogFlowFunc(("Parsing block rc=%Rrc, strmBlockCnt=%ld\n",
{
if (fDrainStream)
{
0 /* Infinite timeout */,
{
{
break;
}
/* Reset found pairs to not break out too early and let all the new
* data to be parsed as well. */
cPairs = 0;
continue; /* Try one more time. */
}
else
{
/* No more output to drain from stream. */
if (rc == VERR_NOT_FOUND)
{
fDrainStream = false;
continue;
}
break;
}
}
else
{
/* We haved drained the stream as much as we can and reached the
* end of our stream buffer -- that means that there simply is no
* stream block anymore, which is ok. */
if (rc == VERR_NO_DATA)
rc = VINF_SUCCESS;
break;
}
}
else
}
while (!cPairs);
LogFlowFunc(("Returned with strmBlockCnt=%ld, cPairs=%ld, rc=%Rrc\n",
return rc;
}
/**
* Tries to get the next upcoming value block from a started guest process
* by first draining its output and then processing the received guest stream.
*
* @return IPRT status code.
* @param ulFlags ?
* @param stream Reference to process stream object to use.
* @param streamBlock Reference that receives the next stream block data.
*
*/
{
int rc;
do
{
if (RT_FAILURE(rc))
break;
}
while (!streamBlock.GetCount());
return rc;
}
/**
* Gets output from a formerly started guest process, tries to parse all of its guest
* stream (as long as data is available) and returns a stream object which can contain
* multiple stream blocks (which in turn then can contain key=value pairs).
*
* @return HRESULT
* @param ulFlags ?
* @param streamObjects Reference to a guest stream object structure for
* storing the parsed data.
*/
HRESULT Guest::executeStreamParse(ULONG ulPID, ULONG ulFlags, GuestCtrlStreamObjects &streamObjects)
{
if (RT_SUCCESS(rc))
{
do
{
/* Try to parse the stream output we gathered until now. If we still need more
* data the parsing routine will tell us and we just do another poll round. */
if (RT_SUCCESS(rc))
} while (RT_SUCCESS(rc));
rc = VINF_SUCCESS;
}
if (RT_FAILURE(rc))
return setError(VBOX_E_IPRT_ERROR,
return rc;
}
/**
* Waits for a fomerly started guest process to exit using its progress
* object and returns its final status. Returns E_ABORT if guest process
* was canceled.
*
* @return IPRT status code.
* @param uPID PID of guest process to wait for.
* @param pProgress Progress object to wait for.
* @param uTimeoutMS Timeout (in ms) for waiting; use 0 for
* an indefinite timeout.
* @param pRetStatus Pointer where to store the final process
* status. Optional.
* @param puRetExitCode Pointer where to store the final process
* exit code. Optional.
*/
{
&& fCanceled)
{
return E_ABORT;
}
&& !fCompleted)
{
? -1 /* No timeout */
: uTimeoutMS);
tr("Waiting for guest process to end failed (%Rhrc)"),
rc);
}
{
return hRC;
if (pRetStatus)
*pRetStatus = enmStatus;
if (puRetExitCode)
/** @todo Flags? */
}
return rc;
}
/**
* Does the actual guest process execution, internal function.
*
* @return HRESULT
* @param aCommand Command line to execute.
* @param aFlags Execution flags.
* @param Username Username to execute the process with.
* @param aPassword The user's password.
* @param aTimeoutMS Timeout (in ms) to wait for the execution operation.
* @param aPID Pointer that receives the guest process' PID.
* @param aProgress Pointer that receives the guest process' progress object.
* @param pRC Pointer that receives the internal IPRT return code. Optional.
*/
{
/** @todo r=bird: Eventually we should clean up all the timeout parameters
* in the API and have the same way of specifying infinite waits! */
using namespace guestControl;
AutoCaller autoCaller(this);
/* Validate flags. */
if (aFlags != ExecuteProcessFlag_None)
{
&& !(aFlags & ExecuteProcessFlag_Hidden)
&& !(aFlags & ExecuteProcessFlag_NoProfile)
&& !(aFlags & ExecuteProcessFlag_WaitForStdErr))
{
if (pRC)
}
}
try
{
/*
* Create progress object. Note that this is a multi operation
* object to perform the following steps:
* - Operation 2 (1): Wait for process to exit.
* If this progress completed successfully (S_OK), the process
* occurred.
*/
{
TRUE,
2, /* Number of operations. */
}
/*
* Prepare process execution.
*/
int vrc = VINF_SUCCESS;
/* Adjust timeout. If set to 0, we define
* an infinite timeout. */
if (aTimeoutMS == 0)
/* Prepare arguments. */
if (aArguments)
{
}
if (RT_SUCCESS(vrc))
{
uint32_t uContextID = 0;
if (uNumArgs > 0)
if (RT_SUCCESS(vrc))
{
/* Prepare environment. */
if (aEnvironment)
{
{
if (RT_FAILURE(vrc))
break;
}
}
if (RT_SUCCESS(vrc))
{
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
{
int i = 0;
/*
* If the WaitForProcessStartOnly flag is set, we only want to define and wait for a timeout
* until the process was started - the process itself then gets an infinite timeout for execution.
* This is handy when we want to start a process inside a worker thread within a certain timeout
* but let the started process perform lengthly operations then.
*/
else
{
/* Make sure mParent is valid, so set the read lock while using.
* Do not keep this lock while doing the actual call, because in the meanwhile
* another thread could request a write lock which would be a bad idea ... */
/* Forward the information to the VMM device. */
}
if (pVMMDev)
{
LogFlowFunc(("hgcmHostCall numParms=%d\n", i));
i, paParms);
}
else
}
}
}
if (RT_SUCCESS(vrc))
{
/*
* Wait for the HGCM low level callback until the process
* has been started (or something went wrong). This is necessary to
* get the PID.
*/
/*
* Wait for the first stage (=0) to complete (that is starting the process).
*/
if (RT_SUCCESS(vrc))
{
if (RT_SUCCESS(vrc))
{
pExecStatus, aPID);
}
else
{
tr("Unable to retrieve process execution status data"));
}
}
else
/*
* Do *not* remove the callback yet - we might wait with the IProgress object on something
* else (like end of process) ...
*/
}
else
for (unsigned i = 0; i < uNumArgs; i++)
}
{
/* Return the progress to the caller. */
}
else
{
if (!pRC) /* Skip logging internal calls. */
LogRel(("Executing guest process \"%s\" as user \"%s\" failed with %Rrc\n",
}
if (pRC)
}
{
rc = E_OUTOFMEMORY;
}
return rc;
}
#endif /* VBOX_WITH_GUEST_CONTROL */
STDMETHODIMP Guest::SetProcessInput(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, ComSafeArrayIn(BYTE, aData), ULONG *aBytesWritten)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
/* Validate flags. */
if (aFlags)
{
if (!(aFlags & ProcessInputFlag_EndOfFile))
}
AutoCaller autoCaller(this);
try
{
if (RT_SUCCESS(vrc))
{
/* PID exists; check if process is still running. */
}
else
if (RT_SUCCESS(vrc))
{
uint32_t uContextID = 0;
/*
* Create progress object.
* This progress object, compared to the one in executeProgress() above,
* is only single-stage local and is used to determine whether the operation
* finished or got canceled.
*/
{
TRUE /* Cancelable */);
}
/* Adjust timeout. */
if (aTimeoutMS == 0)
if (RT_SUCCESS(vrc))
{
/* Save PID + output flags for later use. */
}
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
{
int i = 0;
{
{
/* Make sure mParent is valid, so set the read lock while using.
* Do not keep this lock while doing the actual call, because in the meanwhile
* another thread could request a write lock which would be a bad idea ... */
/* Forward the information to the VMM device. */
}
if (pVMMDev)
{
LogFlowFunc(("hgcmHostCall numParms=%d\n", i));
i, paParms);
if (RT_FAILURE(vrc))
}
}
}
if (RT_SUCCESS(vrc))
{
LogFlowFunc(("Waiting for HGCM callback ...\n"));
/*
* Wait for getting back the input response from the guest.
*/
if (RT_SUCCESS(vrc))
{
if (RT_SUCCESS(vrc))
{
switch (pExecStatusIn->u32Status)
{
case INPUT_STS_WRITTEN:
break;
case INPUT_STS_ERROR:
tr("Client reported error %Rrc while processing input data"),
break;
case INPUT_STS_TERMINATED:
tr("Client terminated while processing input data"));
break;
case INPUT_STS_OVERFLOW:
tr("Client reported buffer overflow while processing input data"));
break;
default:
/*AssertReleaseMsgFailed(("Client reported unknown input error, status=%u, flags=%u\n",
pExecStatusIn->u32Status, pExecStatusIn->u32Flags));*/
break;
}
}
else
{
tr("Unable to retrieve process input status data"));
}
}
else
}
{
/* The callback isn't needed anymore -- just was kept locally. */
}
/* Cleanup. */
}
}
{
rc = E_OUTOFMEMORY;
}
return rc;
#endif
}
STDMETHODIMP Guest::GetProcessOutput(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, LONG64 aSize, ComSafeArrayOut(BYTE, aData))
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
#endif
}
{
/** @todo r=bird: Eventually we should clean up all the timeout parameters
* in the API and have the same way of specifying infinite waits! */
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
if (aSize < 0)
if (aSize == 0)
if (aFlags)
{
if (!(aFlags & ProcessOutputFlag_StdErr))
{
}
}
AutoCaller autoCaller(this);
try
{
if (RT_FAILURE(vrc))
{
}
else
{
uint32_t uContextID = 0;
/*
* Create progress object.
* This progress object, compared to the one in executeProgress() above,
* is only single-stage local and is used to determine whether the operation
* finished or got canceled.
*/
{
TRUE /* Cancelable */);
}
/* Adjust timeout. */
if (aTimeoutMS == 0)
/* Set handle ID. */
if (aFlags & ProcessOutputFlag_StdErr)
/** @todo Use a buffer for next iteration if returned data is too big
* for current read.
* aSize is bogus -- will be ignored atm! */
if (RT_SUCCESS(vrc))
{
/* Save PID + output flags for later use. */
}
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
{
int i = 0;
{
/* Make sure mParent is valid, so set the read lock while using.
* Do not keep this lock while doing the actual call, because in the meanwhile
* another thread could request a write lock which would be a bad idea ... */
/* Forward the information to the VMM device. */
}
if (pVMMDev)
{
LogFlowFunc(("hgcmHostCall numParms=%d\n", i));
i, paParms);
}
}
if (RT_SUCCESS(vrc))
{
/*
* Wait for the HGCM low level callback until the process
* has been started (or something went wrong). This is necessary to
* get the PID.
*/
/*
* Wait for the first output callback notification to arrive.
*/
if (RT_SUCCESS(vrc))
{
if (RT_SUCCESS(vrc))
{
{
bool fResize;
/* Do we need to resize the array? */
{
}
/* Fill output in supplied out buffer. */
}
else
{
/* No data within specified timeout available. */
}
/* Detach output buffer to output argument. */
}
else
{
}
}
else
}
else
{
/* The callback isn't needed anymore -- just was kept locally. */
}
/* Cleanup. */
}
if (pRC)
}
{
rc = E_OUTOFMEMORY;
}
return rc;
#endif
}
STDMETHODIMP Guest::GetProcessStatus(ULONG aPID, ULONG *aExitCode, ULONG *aFlags, ExecuteProcessStatus_T *aStatus)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
AutoCaller autoCaller(this);
try
{
true /* Remove when terminated */);
if (RT_SUCCESS(vrc))
{
if (aExitCode)
if (aFlags)
if (aStatus)
}
else
}
{
rc = E_OUTOFMEMORY;
}
return rc;
#endif
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
/* Do not allow anonymous executions (with system rights). */
AutoCaller autoCaller(this);
/* Validate flags. */
if (aFlags != CopyFileFlag_None)
{
if ( !(aFlags & CopyFileFlag_Recursive)
&& !(aFlags & CopyFileFlag_Update)
&& !(aFlags & CopyFileFlag_FollowLinks))
{
}
}
try
{
/* Create the progress object. */
TRUE /* aCancelable */);
/* Initialize our worker task. */
/* Assign data - aSource is the source file on the host,
* aDest reflects the full path on the guest. */
/* Don't destruct on success. */
}
{
}
{
/* Return progress to the caller. */
}
return rc;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
/* Do not allow anonymous executions (with system rights). */
AutoCaller autoCaller(this);
/* Validate flags. */
if (aFlags != CopyFileFlag_None)
{
if ( !(aFlags & CopyFileFlag_Recursive)
&& !(aFlags & CopyFileFlag_Update)
&& !(aFlags & CopyFileFlag_FollowLinks))
{
}
}
try
{
/* Create the progress object. */
TRUE /* aCancelable */);
/* Initialize our worker task. */
/* Assign data - aSource is the source file on the host,
* aDest reflects the full path on the guest. */
/* Don't destruct on success. */
}
{
}
{
/* Return progress to the caller. */
}
return rc;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
AutoCaller autoCaller(this);
/* Validate flags. */
if (aFlags)
{
}
try
{
/* Create the progress object. */
TRUE /* aCancelable */);
/* Initialize our worker task. */
/* Assign data - in that case aSource is the full path
* to the Guest Additions .ISO we want to mount. */
/* Don't destruct on success. */
}
{
}
{
/* Return progress to the caller. */
}
return rc;
#endif /* VBOX_WITH_GUEST_CONTROL */
}