GuestProcessImpl.cpp revision d3b1b01528fe21777281edf167f8deca06f86e39
/* $Id$ */
/** @file
* VirtualBox Main - XXX.
*/
/*
* Copyright (C) 2012 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.
*/
/**
* Locking rules:
* - When the main dispatcher (callbackDispatcher) is called it takes the
* WriteLock while dispatching to the various on* methods.
* - All other outer functions (accessible by Main) must not own a lock
* while waiting for a callback or for an event.
* - Only keep Read/WriteLocks as short as possible and only when necessary.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "GuestProcessImpl.h"
#include "GuestSessionImpl.h"
#include "GuestCtrlImplPrivate.h"
#include "ConsoleImpl.h"
#include "Global.h"
#include "AutoCaller.h"
#include "VMMDev.h"
#include <memory> /* For auto_ptr. */
#ifdef LOG_GROUP
#endif
#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
class GuestProcessTask
{
public:
mRC(VINF_SUCCESS) { }
virtual ~GuestProcessTask(void) { }
protected:
int mRC;
};
class GuestProcessStartTask : public GuestProcessTask
{
public:
: GuestProcessTask(pProcess) { }
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
mData.mNextContextID = 0;
mData.mProcessID = 0;
mData.mWaitCount = 0;
return hr;
}
void GuestProcess::FinalRelease(void)
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
int GuestProcess::init(Console *aConsole, GuestSession *aSession, ULONG aProcessID, const GuestProcessStartupInfo &aProcInfo)
{
LogFlowThisFunc(("aConsole=%p, aSession=%p, aProcessID=%RU32\n",
/* Enclose the state transition NotReady->InInit->Ready. */
AutoInitSpan autoInitSpan(this);
/* Everything else will be set by the actual starting routine. */
/* Confirm a successful initialization when it's the case. */
return VINF_SUCCESS;
}
/**
* Uninitializes the instance.
* Called from FinalRelease().
*/
void GuestProcess::uninit(void)
{
LogFlowThisFunc(("mCmd=%s, PID=%RU32\n",
/* Enclose the state transition Ready->InUninit->NotReady. */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
int vrc = VINF_SUCCESS;
#ifdef VBOX_WITH_GUEST_CONTROL
/*
* Cancel all callbacks + waiters.
* Note: Deleting them is the job of the caller!
*/
{
if (RT_SUCCESS(vrc))
}
if (mData.mWaitEvent)
{
if (RT_SUCCESS(vrc))
}
#endif
}
/////////////////////////////////////////////////////////////////////////////
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
size_t s = 0;
it++, s++)
{
}
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
{
}
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
// private methods
/////////////////////////////////////////////////////////////////////////////
{
ULONG uSessionID = 0;
/* Create a new context ID and assign it. */
int vrc = VERR_NOT_FOUND;
ULONG uNewContextID = 0;
for (;;)
{
if (uCount == VBOX_GUESTCTRL_MAX_CONTEXTS)
uCount = 0;
/* Create a new context ID ... */
/* Is the context ID already used? Try next ID ... */
if (!callbackExists(uCount))
{
/* Callback with context ID was not found. This means
* we can use this context ID for our new callback we want
* to add below. */
vrc = VINF_SUCCESS;
break;
}
uCount++;
if (++uTries == UINT32_MAX)
break; /* Don't try too hard. */
}
if (RT_SUCCESS(vrc))
{
/* Add callback with new context ID to our callback map.
* Note: This is *not* uNewContextID (which also includes
* the session + process ID), just the context count
* will be used here. */
/* Report back new context ID. */
if (puContextID)
LogFlowThisFunc(("Added new callback (Session: %RU32, Process: %RU32, Count=%RU32) CID=%RU32\n",
}
return vrc;
}
int GuestProcess::callbackDispatcher(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData)
{
#ifdef DEBUG
LogFlowThisFunc(("uPID=%RU32, uContextID=%RU32, uFunction=%RU32, pvData=%p, cbData=%RU32\n",
#endif
int vrc;
/* Get the optional callback associated to this context ID.
* The callback may not be around anymore if just kept locally by the caller when
* doing the actual HGCM sending stuff. */
{
#ifdef DEBUG
LogFlowThisFunc(("pCallback=%p, CID=%RU32, Count=%RU32\n",
#endif
}
switch (uFunction)
{
case GUEST_DISCONNECTED:
{
PCALLBACKDATACLIENTDISCONNECTED pCallbackData = reinterpret_cast<PCALLBACKDATACLIENTDISCONNECTED>(pvData);
AssertReturn(CALLBACKDATAMAGIC_CLIENT_DISCONNECTED == pCallbackData->hdr.u32Magic, VERR_INVALID_PARAMETER);
break;
}
case GUEST_EXEC_SEND_STATUS:
{
break;
}
case GUEST_EXEC_SEND_OUTPUT:
{
break;
}
{
AssertReturn(CALLBACKDATAMAGIC_EXEC_IN_STATUS == pCallbackData->hdr.u32Magic, VERR_INVALID_PARAMETER);
break;
}
default:
/* Silently ignore not implemented functions. */
break;
}
#ifdef DEBUG
#endif
return vrc;
}
{
}
{
LogFlowThisFunc(("Removing callback (Session: %RU32, Process: %RU32, Count=%RU32) CID=%RU32\n",
uContextID));
{
return VINF_SUCCESS;
}
return VERR_NOT_FOUND;
}
/**
* Checks if the current assigned PID matches another PID (from a callback).
*
* processes so it can happen that a formerly start process A
* (which has the context ID 0 (session=0, process=0, count=0) will
* send a delayed message to the host if this process has already
* been discarded there and the same context ID was reused by
* a process B. Process B in turn then has a different guest PID.
*
* @return IPRT status code.
* @param uPID PID to check.
*/
{
/* Was there a PID assigned yet? */
{
/*
*/
{
/* Simply ignore the stale requests. */
}
/* This should never happen! */
AssertReleaseMsg(mData.mPID == uPID, ("Unterminated guest process (PID %RU32) sent data to a newly started process (PID %RU32)\n",
}
return VINF_SUCCESS;
}
/* static */
{
/** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */
switch (guestRc)
{
case VERR_FILE_NOT_FOUND: /* This is the most likely error. */
break;
case VERR_INVALID_VM_HANDLE:
break;
break;
case VERR_PATH_NOT_FOUND:
break;
case VERR_BAD_EXE_FORMAT:
break;
break;
case VERR_INVALID_NAME:
break;
case VERR_TIMEOUT:
break;
case VERR_CANCELLED:
break;
case VERR_PERMISSION_DENIED:
break;
case VERR_MAX_PROCS_REACHED:
break;
case VERR_NOT_EQUAL: /** @todo Imprecise to the user; can mean anything and all. */
break;
case VERR_NOT_FOUND:
break;
default:
break;
}
return strError;
}
inline bool GuestProcess::isAlive(void)
{
}
bool GuestProcess::isReady(void)
{
{
return true;
}
return false;
}
int GuestProcess::onGuestDisconnected(GuestCtrlCallback *pCallback, PCALLBACKDATACLIENTDISCONNECTED pData)
{
/* pCallback is optional. */
/* First, signal callback in every case. */
if (pCallback)
/* Do we need to report a termination? */
else
/* Signal in any case. */
return vrc;
}
int GuestProcess::onProcessInputStatus(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECINSTATUS pData)
{
/* pCallback is optional. */
LogFlowThisFunc(("uPID=%RU32, uStatus=%RU32, uFlags=%RU32, cbProcessed=%RU32, pCallback=%p, pData=%p\n",
if (RT_FAILURE(vrc))
return vrc;
/* First, signal callback in every case (if available). */
if (pCallback)
{
if (RT_SUCCESS(vrc))
}
/* Then do the WaitFor signalling stuff. */
{
if (RT_SUCCESS(vrc))
}
return vrc;
}
{
/* pCallback is optional. */
return 0;
}
int GuestProcess::onProcessStatusChange(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECSTATUS pData)
{
/* pCallback is optional. */
LogFlowThisFunc(("uPID=%RU32, uStatus=%RU32, uFlags=%RU32, pCallback=%p, pData=%p\n",
if (RT_FAILURE(vrc))
return vrc;
int procRc = VINF_SUCCESS;
bool fSignalWaiters = false;
{
case PROC_STS_STARTED:
{
/* If the caller only wants to wait until the process has been started,
* notify in any case. */
fSignalWaiters = true;
break;
}
case PROC_STS_TEN:
{
fSignalWaiters = true; /* Signal in any case. */
break;
}
case PROC_STS_TES:
{
fSignalWaiters = true; /* Signal in any case. */
break;
}
case PROC_STS_TEA:
{
fSignalWaiters = true; /* Signal in any case. */
break;
}
case PROC_STS_TOK:
{
fSignalWaiters = true; /* Signal in any case. */
break;
}
case PROC_STS_TOA:
{
fSignalWaiters = true; /* Signal in any case. */
break;
}
case PROC_STS_DWN:
{
fSignalWaiters = true; /* Signal in any case. */
/* Do we need to report termination? */
else
break;
}
case PROC_STS_ERROR:
{
fSignalWaiters = true; /* Signal in any case. */
procRc = pData->u32Flags; /** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */
break;
}
case PROC_STS_UNDEFINED:
default:
{
/* Silently skip this request. */
fSignalWaiters = true; /* Signal in any case. */
break;
}
}
LogFlowThisFunc(("Got rc=%Rrc, waitRes=%d, procSts=%ld, procRc=%Rrc, fSignalWaiters=%RTbool\n",
/* Set the process status. */
if (RT_SUCCESS(vrc))
/*
* Now do the signalling stuff.
*/
if (pCallback)
if (fSignalWaiters)
{
if (RT_SUCCESS(vrc))
}
return vrc;
}
{
/* pCallback is optional. */
LogFlowThisFunc(("uPID=%RU32, uHandle=%RU32, uFlags=%RU32, pvData=%p, cbData=%RU32, pCallback=%p, pData=%p\n",
if (RT_FAILURE(vrc))
return vrc;
/* First, signal callback in every case (if available). */
if (pCallback)
{
if (RT_SUCCESS(vrc))
}
/* Then do the WaitFor signalling stuff. */
if ( (uWaitFlags & ProcessWaitForFlag_StdOut)
|| (uWaitFlags & ProcessWaitForFlag_StdErr))
{
}
else if ( (uWaitFlags & ProcessWaitForFlag_StdOut)
{
}
else if ( (uWaitFlags & ProcessWaitForFlag_StdErr)
{
}
if (fSignal)
{
int rc2;
else
if (RT_SUCCESS(vrc))
}
return vrc;
}
{
LogFlowThisFunc(("uPID=%RU32, uHandle=%RU32, uSize=%RU32, uTimeoutMS=%RU32, pvData=%p, cbData=%RU32, pGuestRc=%p\n",
/* pcbRead is optional. */
{
if (pcbRead)
*pcbRead = 0;
if (pGuestRc)
*pGuestRc = VINF_SUCCESS;
return VINF_SUCCESS; /* Nothing to read anymore. */
}
int vrc = VINF_SUCCESS;
try
{
pCallbackRead = new GuestCtrlCallback();
}
{
}
/* Create callback and add it to the map. */
uint32_t uContextID = 0;
if (RT_SUCCESS(vrc))
{
if (RT_SUCCESS(vrc))
}
if (RT_SUCCESS(vrc))
{
int i = 0;
}
if (RT_SUCCESS(vrc))
{
/*
* Let's wait for the process being started.
*/
{
LogFlowThisFunc(("Callback returned rc=%Rrc, cbData=%RU32\n", guestRc, pCallbackRead->GetDataSize()));
if (RT_SUCCESS(guestRc))
{
if (cbRead)
{
}
if (pcbRead)
}
else
if (pGuestRc)
}
}
if (RT_SUCCESS(vrc))
return vrc;
}
{
/* Forward the information to the VMM device. */
if (RT_FAILURE(vrc))
{
}
return vrc;
}
/* Does not do locking; caller is responsible for that! */
{
LogFlowThisFunc(("oldStatus=%ld, newStatus=%ld, procRc=%Rrc\n",
#ifdef DEBUG
if (procStatus == ProcessStatus_Error)
{
/* Do not allow overwriting an already set error. If this happens
}
else
#endif
return VINF_SUCCESS;
}
/* static */
{
}
{
LogFlowThisFunc(("enmWaitResult=%d, rc=%Rrc, mWaitCount=%RU32, mWaitEvent=%p\n",
/* Note: No write locking here -- already done in the caller. */
int vrc = VINF_SUCCESS;
if (mData.mWaitEvent)
return vrc;
}
{
LogFlowThisFunc(("aCmd=%s, aTimeoutMS=%RU32, fFlags=%x\n",
/* Wait until the caller function (if kicked off by a thread)
* has returned and continue operation. */
int vrc = VINF_SUCCESS;
uint32_t uContextID = 0;
try
{
pCallbackStart = new GuestCtrlCallback();
}
{
}
if (RT_SUCCESS(vrc))
{
/* Create callback and add it to the map. */
if (RT_SUCCESS(vrc))
}
if (RT_SUCCESS(vrc))
{
/* Prepare arguments. */
if (cArgs >= UINT32_MAX)
if ( RT_SUCCESS(vrc)
&& cArgs)
{
{
}
if (RT_SUCCESS(vrc))
if (papszArgv)
{
size_t i = 0;
while (papszArgv[i])
}
}
/* Calculate arguments size (in bytes). */
if (RT_SUCCESS(vrc))
/* Prepare environment. */
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
{
/* Prepare HGCM call. */
int i = 0;
paParms[i++].setPointer((void*)sessionCreds.mPassword.c_str(), (ULONG)sessionCreds.mPassword.length() + 1);
/** @todo New command needs the domain as well! */
/*
* 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
/* Note: Don't hold the write lock in here, because setErrorInternal */
}
if (pszArgs)
/* Drop the write lock again before waiting. */
if (RT_SUCCESS(vrc))
{
/*
* Let's wait for the process being started.
*/
{
if (pGuestRc)
}
else
vrc = VERR_TIMEOUT;
}
if (RT_SUCCESS(vrc))
}
return vrc;
}
int GuestProcess::startProcessAsync(void)
{
int vrc;
try
{
/* Asynchronously start the process on the guest by kicking off a
* worker thread. */
"gctlPrcStart");
if (RT_SUCCESS(vrc))
{
/* pTask is now owned by startProcessThread(), so release it. */
}
}
{
}
return vrc;
}
/* static */
{
/* Nothing to do here anymore. */
return vrc;
}
int GuestProcess::terminateProcess(void)
{
return VERR_NOT_SUPPORTED;
return VERR_NOT_IMPLEMENTED;
}
int GuestProcess::waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, ProcessWaitResult_T &waitResult, int *pGuestRc)
{
LogFlowThisFunc(("fWaitFlags=0x%x, uTimeoutMS=%RU32, mStatus=%RU32, mWaitCount=%RU32, mWaitEvent=%p, pGuestRc=%p\n",
/* Did some error occur before? Then skip waiting and return. */
{
AssertMsg(RT_FAILURE(mData.mRC), ("No error rc (%Rrc) set when guest process indicated an error\n", mData.mRC));
if (pGuestRc)
return VERR_GENERAL_FAILURE; /** @todo Special guest control rc needed! */
}
if ( (fWaitFlags & ProcessWaitForFlag_Terminate)
|| (fWaitFlags & ProcessWaitForFlag_StdErr))
{
{
case ProcessStatus_Down:
break;
break;
case ProcessStatus_Error:
/* Handled above. */
break;
case ProcessStatus_Started:
{
/*
* If ProcessCreateFlag_WaitForProcessStartOnly was specified on process creation the
* caller is not interested in getting further process statuses -- so just don't notify
* anything here anymore and return.
*/
break;
}
case ProcessStatus_Undefined:
case ProcessStatus_Starting:
/* Do the waiting below. */
break;
default:
return VERR_NOT_IMPLEMENTED;
}
}
else if (fWaitFlags & ProcessWaitForFlag_Start)
{
{
case ProcessStatus_Started:
case ProcessStatus_Paused:
case ProcessStatus_Down:
break;
case ProcessStatus_Error:
break;
break;
case ProcessStatus_Undefined:
case ProcessStatus_Starting:
/* Do the waiting below. */
break;
default:
return VERR_NOT_IMPLEMENTED;
}
}
/* Filter out waits which are *not* supported using
* older guest control Guest Additions. */
{
if ( waitResult == ProcessWaitResult_None
/* We don't support waiting for stdin, out + err,
* just skip waiting then. */
&& ( (fWaitFlags & ProcessWaitForFlag_StdIn)
)
)
{
/* Use _WaitFlagNotSupported because we don't know what to tell the caller. */
}
}
LogFlowThisFunc(("procStatus=%ld, procRc=%Rrc, waitResult=%ld\n",
/* No waiting needed? Return immediately using the last set error. */
if (waitResult != ProcessWaitResult_None)
{
if (pGuestRc)
return RT_SUCCESS(mData.mRC) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Special guest control rc needed! */
}
if (mData.mWaitCount > 0)
return VERR_ALREADY_EXISTS;
mData.mWaitCount++;
int vrc = VINF_SUCCESS;
try
{
}
{
}
if (RT_SUCCESS(vrc))
{
if (RT_SUCCESS(vrc))
{
if (pGuestRc)
vrc = RT_SUCCESS(waitRc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Special guest control rc needed! */
}
/* Note: The caller always is responsible of deleting the
* stuff it created before. See close() for more information. */
delete mData.mWaitEvent;
}
mData.mWaitCount--;
return vrc;
}
{
LogFlowThisFunc(("uPID=%RU32, uHandle=%RU32, uFlags=%RU32, pvData=%p, cbData=%RU32, uTimeoutMS=%RU32, puWritten=%p, pGuestRc=%p\n",
/* All is optional. There can be 0 byte writes. */
{
if (puWritten)
*puWritten = 0;
if (pGuestRc)
*pGuestRc = VINF_SUCCESS;
return VINF_SUCCESS; /* Not available for writing (anymore). */
}
int vrc = VINF_SUCCESS;
try
{
pCallbackWrite = new GuestCtrlCallback();
}
{
}
/* Create callback and add it to the map. */
uint32_t uContextID = 0;
if (RT_SUCCESS(vrc))
{
if (RT_SUCCESS(vrc))
}
if (RT_SUCCESS(vrc))
{
int i = 0;
}
if (RT_SUCCESS(vrc))
{
/*
* Let's wait for the process being started.
*/
{
LogFlowThisFunc(("Callback returned rc=%Rrc, cbData=%RU32\n", guestRc, pCallbackWrite->GetDataSize()));
if (RT_SUCCESS(guestRc))
{
{
case INPUT_STS_WRITTEN:
break;
case INPUT_STS_ERROR:
break;
case INPUT_STS_TERMINATED:
break;
case INPUT_STS_OVERFLOW:
break;
default:
/* Silently skip unknown errors. */
break;
}
if (pGuestRc)
if (puWritten)
if (RT_FAILURE(guestRc))
}
}
}
if (RT_SUCCESS(vrc))
return vrc;
}
// implementation of public methods
/////////////////////////////////////////////////////////////////////////////
STDMETHODIMP GuestProcess::Read(ULONG aHandle, ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData))
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
if (aToRead == 0)
AutoCaller autoCaller(this);
if (RT_SUCCESS(vrc))
{
}
else
{
switch (vrc)
{
case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
break;
default:
tr("Reading from process \"%s\" (PID %RU32) failed: %Rrc"),
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
int vrc = terminateProcess();
if (RT_FAILURE(vrc))
{
switch (vrc)
{
case VERR_NOT_IMPLEMENTED:
break; /* Never reached. */
case VERR_NOT_SUPPORTED:
tr("Terminating process \"%s\" (PID %RU32) not supported by installed Guest Additions"),
break;
default:
tr("Terminating process \"%s\" (PID %RU32) failed: %Rrc"),
break;
}
}
/*
* Release autocaller before calling uninit.
*/
uninit();
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestProcess::WaitFor(ULONG aWaitFlags, ULONG aTimeoutMS, ProcessWaitResult_T *aReason)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
/*
* Note: Do not hold any locks here while waiting!
*/
if (RT_SUCCESS(vrc))
{
*aReason = waitResult;
}
else
{
switch (vrc)
{
case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
break;
case VERR_TIMEOUT:
break;
default:
tr("Waiting for process \"%s\" (PID %RU32) failed: %Rrc"),
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestProcess::WaitForArray(ComSafeArrayIn(ProcessWaitForFlag_T, aFlags), ULONG aTimeoutMS, ProcessWaitResult_T *aReason)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
/*
* Note: Do not hold any locks here while waiting!
*/
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
int vrc = writeData(aHandle, aFlags, data.raw(), data.size(), aTimeoutMS, (uint32_t*)aWritten, &guestRc);
if (RT_FAILURE(vrc))
{
switch (vrc)
{
case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
break;
default:
tr("Writing to process \"%s\" (PID %RU32) failed: %Rrc"),
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
/*
* Note: Do not hold any locks here while writing!
*/
#endif /* VBOX_WITH_GUEST_CONTROL */
}
///////////////////////////////////////////////////////////////////////////////
GuestProcessTool::GuestProcessTool(void)
{
}
GuestProcessTool::~GuestProcessTool(void)
{
Terminate();
}
{
LogFlowThisFunc(("pGuestSession=%p, szCmd=%s, fAsync=%RTbool\n",
/* Make sure the process is hidden. */
if (RT_SUCCESS(vrc))
if ( !fAsync
&& ( pGuestRc
&& RT_FAILURE(*pGuestRc)
)
)
{
}
return vrc;
}
{
if (uHandle == OUTPUT_HANDLE_ID_STDOUT)
else if (uHandle == OUTPUT_HANDLE_ID_STDERR)
if (!pStream)
return VERR_INVALID_PARAMETER;
int vrc;
do
{
/* Try parsing the data to see if the current block is complete. */
break;
} while (RT_SUCCESS(vrc));
LogFlowThisFunc(("rc=%Rrc, %RU64 pairs\n",
return vrc;
}
bool GuestProcessTool::IsRunning(void)
{
if ( procStatus != ProcessStatus_Started
{
return false;
}
return true;
}
{
/* pExitCode is optional. */
if (!IsRunning())
{
if (pExitCode)
if (exitCode != 0)
return VERR_NOT_EQUAL; /** @todo Special guest control rc needed! */
return VINF_SUCCESS;
}
return VERR_INVALID_STATE; /** @todo Special guest control rc needed! */
}
{
}
{
LogFlowThisFunc(("pSession=%p, fFlags=0x%x, pStreamBlock=%p, pGuestRc=%p\n",
/* Other parameters are optional. */
/* Can we parse the next block without waiting? */
int vrc;
{
if (RT_SUCCESS(vrc))
return vrc;
}
/* Do the waiting. */
/** @todo Decrease timeout. */
int guestRc;
bool fDone = false;
bool fHandleStdOut = false;
bool fHandleStdErr = false;
do
{
if (RT_FAILURE(vrc))
break;
switch (waitRes)
{
case ProcessWaitResult_StdIn:
/* Nothing to do here yet. */
fDone = true;
break;
case ProcessWaitResult_StdOut:
fHandleStdOut = true;
break;
case ProcessWaitResult_StdErr:
fHandleStdErr = true;
break;
fHandleStdOut = true;
fHandleStdErr = true;
/* Since waiting for stdout / stderr is not supported by the guest,
* wait a bit to not hog the CPU too much when polling for data. */
break;
case ProcessWaitResult_Error:
break;
fDone = true;
break;
vrc = VERR_TIMEOUT;
break;
default:
fDone = true;
break;
}
if (fHandleStdOut)
{
if (RT_FAILURE(vrc))
break;
if (cbRead)
{
if ( RT_SUCCESS(vrc)
{
if (RT_SUCCESS(vrc))
fDone = true;
}
}
fHandleStdOut = false;
}
if (fHandleStdErr)
{
if (RT_FAILURE(vrc))
break;
if (cbRead)
{
}
fHandleStdErr = false;
}
LogFlowThisFunc(("Loop ended with rc=%Rrc, guestRc=%Rrc, waitRes=%ld\n",
if (pGuestRc)
return vrc;
}
void GuestProcessTool::Terminate(void)
{
{
/** @todo Add pProcess.Terminate() here as soon as it's implemented. */
}
}