VBoxServiceControlThread.cpp revision 862ba4401c9fa66fbb0264053634d47d0718ed74
/* $Id$ */
/** @file
* VBoxServiceControlExecThread - Thread for every started guest process.
*/
/*
* Copyright (C) 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/semaphore.h>
#include <VBox/VBoxGuestLib.h>
#include "VBoxServiceInternal.h"
using namespace guestControl;
/* Internal functions. */
/**
* Initialies the passed in thread data structure with the parameters given.
*
* @return IPRT status code.
* @param pThread The thread's handle to allocate the data for.
* @param u32ContextID The context ID bound to this request / command.
@ @param pProcess Process information.
*/
{
/* General stuff. */
/* ClientID will be assigned when thread is started; every guest
* process has its own client ID to detect crashes on a per-guest-process
* level. */
if (RT_FAILURE(rc))
return rc;
|| pProcess->uTimeLimitMS == 0)
/* Prepare argument list. */
/* Did we get the same result? */
if (RT_SUCCESS(rc))
{
/* Prepare environment list. */
pThread->uNumEnvVars = 0;
if (pProcess->uNumEnvVars)
{
uint32_t i = 0;
{
/* sanity check */
if (i >= pProcess->uNumEnvVars)
{
break;
}
if (cbStr < 0)
{
break;
}
}
}
/* The actual command to execute. */
/* User management. */
}
return rc;
}
/**
* Frees a guest thread.
*
* @return IPRT status code.
* @param pThread Thread to shut down.
*/
{
if (RT_SUCCESS(rc))
{
if (pThread->uNumEnvVars)
{
}
}
/*
* Destroy other thread data.
*/
/*
* Destroy thread structure as final step.
*/
return rc;
}
/**
* Signals a guest process thread that we want it to shut down in
* a gentle way.
*
* @return IPRT status code.
* @param pThread Thread to shut down.
*/
{
if (RT_FAILURE(rc))
VBoxServiceError("ControlThread: [PID %u]: Signalling request event failed, rc=%Rrc\n",
/* Do *not* set pThread->fShutdown or other stuff here!
* The guest thread loop will do that as soon as it processes the quit message. */
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
}
return rc;
}
/**
* Wait for a guest process thread to shut down.
*
* @return IPRT status code.
* @param pThread Thread to wait shutting down for.
* @param RTMSINTERVAL Timeout in ms to wait for shutdown.
*/
{
int rc = VINF_SUCCESS;
{
/* Wait a bit ... */
int rcThread;
if (RT_FAILURE(rc))
{
VBoxServiceError("ControlThread: [PID %u]: Waiting for shutting down thread returned error rc=%Rrc\n",
}
else
{
if (RT_FAILURE(rcThread))
{
VBoxServiceError("ControlThread: [PID %u]: Shutdown returned error rc=%Rrc\n",
}
}
}
return rc;
}
/**
* Closes the stdin pipe of a guest process.
*
* @return IPRT status code.
* @param hPollSet The polling set.
* @param phStdInW The standard input pipe handle.
*/
{
if (rc != VERR_POLL_HANDLE_ID_NOT_FOUND)
if (*phStdInW != NIL_RTPIPE)
{
*phStdInW = NIL_RTPIPE;
}
return rc;
}
/**
* Handle an error event on standard input.
*
* @return IPRT status code.
* @param hPollSet The polling set.
* @param fPollEvt The event mask returned by RTPollNoResume.
* @param phStdInW The standard input pipe handle.
*/
static int VBoxServiceControlThreadHandleStdInErrorEvent(RTPOLLSET hPollSet, uint32_t fPollEvt, PRTPIPE phStdInW)
{
}
/**
* Handle pending output data or error on standard out or standard error.
*
* @returns IPRT status code from client send.
* @param hPollSet The polling set.
* @param fPollEvt The event mask returned by RTPollNoResume.
* @param phPipeR The pipe handle.
* @param idPollHnd The pipe ID to handle.
*
*/
{
#ifdef DEBUG
VBoxServiceVerbose(4, "ControlThread: VBoxServiceControlThreadHandleOutputError: fPollEvt=0x%x, idPollHnd=%u\n",
#endif
/* Remove pipe from poll set. */
bool fClosePipe = true; /* By default close the pipe. */
/* Check if there's remaining data to read from the pipe. */
if ( RT_SUCCESS(rc2)
&& cbReadable)
{
VBoxServiceVerbose(3, "ControlThread: VBoxServiceControlThreadHandleOutputError: idPollHnd=%u has %ld bytes left, vetoing close\n",
/* Veto closing the pipe yet because there's still stuff to read
* from the pipe. This can happen on UNIX-y systems where on
fClosePipe = false;
}
else
VBoxServiceVerbose(3, "ControlThread: VBoxServiceControlThreadHandleOutputError: idPollHnd=%u will be closed\n",
if ( *phPipeR != NIL_RTPIPE
&& fClosePipe)
{
*phPipeR = NIL_RTPIPE;
}
return VINF_SUCCESS;
}
/**
* Handle pending output data or error on standard out or standard error.
*
* @returns IPRT status code from client send.
* @param hPollSet The polling set.
* @param fPollEvt The event mask returned by RTPollNoResume.
* @param phPipeR The pipe handle.
* @param idPollHnd The pipe ID to handle.
*
*/
{
#if 0
VBoxServiceVerbose(4, "ControlThread: VBoxServiceControlThreadHandleOutputEvent: fPollEvt=0x%x, idPollHnd=%u\n",
#endif
int rc = VINF_SUCCESS;
#ifdef DEBUG
if ( RT_SUCCESS(rc)
&& cbReadable)
{
}
#endif
#if 0
//if (fPollEvt & RTPOLL_EVT_READ)
{
VBoxServiceVerbose(4, "ControlThread: VBoxServiceControlThreadHandleOutputEvent cbRead=%u, rc=%Rrc\n",
/* Make sure we go another poll round in case there was too much data
for the buffer to hold. */
}
#endif
if (fPollEvt & RTPOLL_EVT_ERROR)
return rc;
}
{
/* Drain the notification pipe. */
if (RT_FAILURE(rc))
if (!pRequest)
{
VBoxServiceError("ControlThread: IPC request is invalid\n");
return VERR_INVALID_POINTER;
}
{
case VBOXSERVICECTRLREQUEST_QUIT: /* Main control asked us to quit. */
{
/** @todo Check for some conditions to check to
* veto quitting. */
break;
}
{
{
if (*phStdInW != NIL_RTPIPE)
{
}
else
}
/*
* If this is the last write + we have really have written all data
* we need to close the stdin pipe on our end and remove it from
* the poll set.
*/
{
}
/* Reqport back actual data written (if any). */
break;
}
{
if (*pPipeR != NIL_RTPIPE)
{
if (RT_FAILURE(rcReq))
{
*pPipeR = NIL_RTPIPE;
if (rcReq == VERR_BROKEN_PIPE)
}
}
else
/* Report back actual data read (if any). */
break;
}
default:
break;
}
/* Assign overall result. */
/* In any case, regardless of the result, we notify
* the main guest control to unblock it. */
/* No access to pRequest here anymore -- could be out of scope
* or modified already! */
return rc;
}
/**
* Execution loop which runs in a dedicated per-started-process thread and
*
* @return IPRT status code.
* @param pThread The process' thread handle.
* @param hProcess The actual process handle.
* @param cMsTimeout Time limit (in ms) of the process' life time.
* @param hPollSet The poll set to use.
* @param hStdInW Handle to the process' stdin write end.
* @param hStdOutR Handle to the process' stdout read end.
* @param hStdErrR Handle to the process' stderr read end.
*/
{
/* Rest is optional. */
int rc;
int rc2;
bool fProcessAlive = true;
bool fProcessTimedOut = false;
? 100 /* Need to poll for input. */
: 1000; /* Need only poll for process exit and aborts. */
RTMSINTERVAL cMsPollCur = 0;
/*
* Assign PID to thread data.
* Also check if there already was a thread with the same PID and shut it down -- otherwise
* the first (stale) entry will be found and we get really weird results!
*/
if (RT_FAILURE(rc))
{
VBoxServiceError("ControlThread: Unable to assign PID=%u, to new thread, rc=%Rrc\n",
return rc;
}
/*
* Before entering the loop, tell the host that we've started the guest
* and that it's now OK to send input to the process.
*/
/*
* Process input, output, the test pipe and client requests.
*/
while ( RT_SUCCESS(rc)
{
/*
*/
continue;
cMsPollCur = 0; /* No rest until we've checked everything. */
if (RT_SUCCESS(rc2))
{
/*VBoxServiceVerbose(4, "ControlThread: [PID %u}: RTPollNoResume idPollHnd=%u\n",
pThread->uPID, idPollHnd);*/
switch (idPollHnd)
{
break;
break;
break;
break;
}
break; /* Abort command, or client dead or something. */
break; /* We were asked to shutdown. */
continue;
}
#if 0
VBoxServiceVerbose(4, "ControlThread: [PID %u]: Polling done, pollRC=%Rrc, pollCnt=%u, rc=%Rrc, fShutdown=%RTbool\n",
#endif
/*
* Check for process death.
*/
if (fProcessAlive)
{
if (RT_SUCCESS_NP(rc2))
{
fProcessAlive = false;
continue;
}
continue;
{
fProcessAlive = false;
AssertFailed();
}
else
}
/*
* If the process has terminated and all output has been consumed,
* we should be heading out.
*/
if ( !fProcessAlive
&& *phStdOutR == NIL_RTPIPE
&& *phStdErrR == NIL_RTPIPE)
break;
/*
* Check for timed out, killing the process.
*/
if (cMsTimeout != RT_INDEFINITE_WAIT)
{
if (cMsElapsed >= cMsTimeout)
{
VBoxServiceVerbose(3, "ControlThread: [PID %u]: Timed out (%ums elapsed > %ums timeout), killing ...",
fProcessTimedOut = true;
if ( MsProcessKilled == UINT64_MAX
{
break; /* Give up after 20 mins. */
continue;
}
cMilliesLeft = 10000;
}
else
}
/* Reset the polling interval since we've done all pending work. */
: RT_MS_1MIN;
if (cMilliesLeft < cMsPollCur)
/*
* Need to exit?
*/
break;
}
if (RT_SUCCESS(rc2))
{
}
/*
* Try kill the process if it's still alive at this point.
*/
if (fProcessAlive)
{
if (MsProcessKilled == UINT64_MAX)
{
RTThreadSleep(500);
}
for (size_t i = 0; i < 10; i++)
{
if (RT_SUCCESS(rc2))
{
fProcessAlive = false;
break;
}
if (i >= 5)
{
}
}
if (fProcessAlive)
}
/*
* If we don't have a client problem (RT_FAILURE(rc)) we'll reply to the
* clients exec packet now.
*/
if (RT_SUCCESS(rc))
{
{
}
{
}
{
VBoxServiceVerbose(3, "ControlThread: [PID %u]: Got terminated because system/service is about to shutdown\n",
}
else if (fProcessAlive)
{
VBoxServiceError("ControlThread: [PID %u]: Is alive when it should not!\n",
}
else if (MsProcessKilled != UINT64_MAX)
{
VBoxServiceError("ControlThread: [PID %u]: Has been killed when it should not!\n",
}
{
VBoxServiceVerbose(3, "ControlThread: [PID %u]: Ended with RTPROCEXITREASON_NORMAL (Exit code: %u)\n",
}
{
}
{
/* ProcessStatus.iStatus will be undefined. */
}
else
VBoxServiceVerbose(2, "ControlThread: [PID %u]: Ended, ClientID=%u, CID=%u, Status=%u, Flags=0x%x\n",
if (RT_FAILURE(rc))
VBoxServiceError("ControlThread: [PID %u]: Error reporting final status to host; rc=%Rrc\n",
}
else
VBoxServiceError("ControlThread: [PID %u]: Loop failed with rc=%Rrc\n",
return rc;
}
/**
* Initializes a pipe's handle and pipe object.
*
* @return IPRT status code.
* @param ph The pipe's handle to initialize.
* @param phPipe The pipe's object to initialize.
*/
{
*phPipe = NIL_RTPIPE;
return VINF_SUCCESS;
}
/**
* Allocates a guest thread request with the specified request data.
*
* @return IPRT status code.
* @param ppReq Pointer that will receive the newly allocated request.
* Must be freed later with VBoxServiceControlThreadRequestFree().
* @param enmType Request type.
* @param pbData Payload data, based on request type.
* @param cbData Size of payload data (in bytes).
* @param uCID Context ID to which this request belongs to.
*/
void* pbData,
{
RTMemAlloc(sizeof(VBOXSERVICECTRLREQUEST));
/* Set request result to some defined state in case
* it got cancelled. */
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return rc;
}
/**
* Allocates a guest thread request with the specified request data.
*
* @return IPRT status code.
* @param ppReq Pointer that will receive the newly allocated request.
* Must be freed later with VBoxServiceControlThreadRequestFree().
* @param enmType Request type.
*/
{
0 /* ContextID */);
}
/**
* Cancels a previously fired off guest thread request.
*
* Note: Does *not* do locking since VBoxServiceControlThreadRequestWait()
* holds the lock (critsect); so only trigger the signal; the owner
* needs to clean up afterwards.
*
* @return IPRT status code.
* @param pReq Request to cancel.
*/
{
if (!pReq) /* Silently skip non-initialized requests. */
return VINF_SUCCESS;
}
/**
* Frees a formerly allocated guest thread request.
*
* @return IPRT status code.
* @param pReq Request to free.
*/
{
}
/**
* Waits for a guest thread's event to get triggered.
*
* @return IPRT status code.
* @param pReq Request to wait for.
*/
{
if (RT_SUCCESS(rc))
{
/* Give back overall request result. */
}
else
return rc;
}
/**
* Sets up the redirection / pipe / nothing for one of the standard handles.
*
* @returns IPRT status code. No client replies made.
* @param pszHowTo How to set up this standard handle.
* @param fd Which standard handle it is (0 == stdin, 1 ==
* stdout, 2 == stderr).
* @param ph The generic handle that @a pph may be set
* pointing to. Always set.
* @param pph Pointer to the RTProcCreateExec argument.
* Always set.
* @param phPipe Where to return the end of the pipe that we
* should service.
*/
{
int rc;
*phPipe = NIL_RTPIPE;
{
/*
* to represent the "other" end to phPipe.
*/
if (fd == 0) /* stdin? */
{
/* Connect a wrtie pipe specified by phPipe to stdin. */
}
else /* stdout or stderr? */
{
/* Connect a read pipe specified by phPipe to stdout or stderr. */
}
if (RT_FAILURE(rc))
return rc;
}
{
/*
*/
if (RT_FAILURE(rc))
return rc;
}
else /* Add other piping stuff here. */
return rc;
}
/**
* Expands a file name / path to its real content. This only works on Windows
* for now (e.g. translating "%TEMP%\foo.exe" to "C:\Windows\Temp" when starting
* with system / administrative rights).
*
* @return IPRT status code.
* @param pszPath Path to resolve.
* @param pszExpanded Pointer to string to store the resolved path in.
* @param cbExpanded Size (in bytes) of string to store the resolved path.
*/
static int VBoxServiceControlThreadMakeFullPath(const char *pszPath, char *pszExpanded, size_t cbExpanded)
{
int rc = VINF_SUCCESS;
#ifdef RT_OS_WINDOWS
#else
/* No expansion for non-Windows yet. */
#endif
#ifdef DEBUG
#endif
return rc;
}
/**
* Resolves the full path of a specified executable name. This function also
* resolves internal VBoxService tools to its appropriate executable path + name.
*
* @return IPRT status code.
* @param pszFileName File name to resovle.
* @param pszResolved Pointer to a string where the resolved file name will be stored.
* @param cbResolved Size (in bytes) of resolved file name string.
*/
static int VBoxServiceControlThreadResolveExecutable(const char *pszFileName,
{
int rc = VINF_SUCCESS;
/* Search the path of our executable. */
char szVBoxService[RTPATH_MAX];
{
char *pszExecResolved = NULL;
{
/* We just want to execute VBoxService (no toolbox). */
}
else /* Nothing to resolve, copy original. */
#ifdef DEBUG
#endif
}
return rc;
}
/**
* Constructs the argv command line by resolving environment variables
* and relative paths.
*
* @return IPRT status code.
* @param pszArgv0 First argument (argv0), either original or modified version.
* @param papszArgs Original argv command line from the host, starting at argv[1].
* @param ppapszArgv Pointer to a pointer with the new argv command line.
* Needs to be freed with RTGetOptArgvFree.
*/
static int VBoxServiceControlThreadPrepareArgv(const char *pszArgv0,
const char * const *papszArgs, char ***ppapszArgv)
{
/** @todo RTGetOptArgvToString converts to MSC quoted string, while
* RTGetOptArgvFromString takes bourne shell according to the docs...
* Actually, converting to and from here is a very roundabout way of prepending
* an entry (pszFilename) to an array (*ppapszArgv). */
int rc = VINF_SUCCESS;
char *pszNewArgs = NULL;
if (pszArgv0)
if ( RT_SUCCESS(rc)
&& papszArgs)
{
char *pszArgs;
RTGETOPTARGV_CNV_QUOTE_MS_CRT); /* RTGETOPTARGV_CNV_QUOTE_BOURNE_SH */
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
}
}
if (RT_SUCCESS(rc))
{
int iNumArgsIgnored;
}
if (pszNewArgs)
return rc;
}
/**
*
* @return IPRT status code.
* @param pszExec Full qualified path of process to start (without arguments).
* @param papszArgs Pointer to array of command line arguments.
* @param hEnv Handle to environment block to use.
* @param fFlags Process execution flags.
* @param phStdIn Handle for the process' stdin pipe.
* @param phStdOut Handle for the process' stdout pipe.
* @param phStdErr Handle for the process' stderr pipe.
* @param pszAsUser User name (account) to start the process under.
* @param pszPassword Password of the specified user.
* @param phProcess Pointer which will receive the process handle after
* successful process start.
*/
static int VBoxServiceControlThreadCreateProcess(const char *pszExec, const char * const *papszArgs, RTENV hEnv, uint32_t fFlags,
{
int rc = VINF_SUCCESS;
char szExecExp[RTPATH_MAX];
#ifdef RT_OS_WINDOWS
/*
* If sysprep should be executed do this in the context of VBoxService, which
* (usually, if started by SCM) has administrator rights. Because of that a UI
* won't be shown (doesn't have a desktop).
*/
{
/* Use a predefined sysprep path as default. */
/*
* On Windows Vista (and up) sysprep is located in "system32\\sysprep\\sysprep.exe",
* so detect the OS and use a different path.
*/
{
if (RT_SUCCESS(rc))
}
if (RT_SUCCESS(rc))
{
char **papszArgsExp;
if (RT_SUCCESS(rc))
{
}
}
return rc;
}
#endif /* RT_OS_WINDOWS */
#ifdef VBOXSERVICE_TOOLBOX
{
/* We want to use the internal toolbox (all internal
* tools are starting with "vbox_" (e.g. "vbox_cat"). */
}
else
{
#endif
/*
* Do the environment variables expansion on executable and arguments.
*/
#ifdef VBOXSERVICE_TOOLBOX
}
#endif
if (RT_SUCCESS(rc))
{
char **papszArgsExp;
rc = VBoxServiceControlThreadPrepareArgv(pszExec /* Always use the unmodified executable name as argv0. */,
if (RT_SUCCESS(rc))
{
uint32_t uProcFlags = 0;
if (fFlags)
{
if (fFlags & EXECUTEPROCESSFLAG_HIDDEN)
}
/* If no user name specified run with current credentials (e.g.
*
* Otherwise use the RTPROC_FLAGS_SERVICE to use some special authentication
* code (at least on Windows) for running processes as different users
* started from our system service. */
if (*pszAsUser)
#ifdef DEBUG
for (size_t i = 0; papszArgsExp[i]; i++)
#endif
/* Do normal execution. */
}
}
return rc;
}
/**
* The actual worker routine (loop) for a started guest process.
*
* @return IPRT status code.
* @param PVBOXSERVICECTRLTHREAD Thread data associated with a started process.
*/
{
if (RT_FAILURE(rc))
{
VBoxServiceError("ControlThread: Thread failed to connect to the guest control service, aborted! Error: %Rrc\n", rc);
return rc;
}
bool fSignalled = false; /* Indicator whether we signalled the thread user event already. */
/*
* Create the environment.
*/
if (RT_SUCCESS(rc))
{
size_t i;
{
if (RT_FAILURE(rc))
break;
}
if (RT_SUCCESS(rc))
{
/*
* Setup the redirection of the standard stuff.
*/
/** @todo consider supporting: gcc stuff.c >file 2>&1. */
if (RT_SUCCESS(rc))
{
1 /*STDOUT_FILENO*/,
if (RT_SUCCESS(rc))
{
2 /*STDERR_FILENO*/,
if (RT_SUCCESS(rc))
{
/*
* Create a poll set for the pipes and let the
* transport layer add stuff to it as well.
*/
if (RT_SUCCESS(rc))
{
#if 0
/* Add reading event to pollset to get some more information. */
#endif
/* Stdin. */
if (RT_SUCCESS(rc))
rc = RTPollSetAddPipe(hPollSet, pThread->pipeStdInW, RTPOLL_EVT_ERROR, VBOXSERVICECTRLPIPEID_STDIN);
/* Stdout. */
if (RT_SUCCESS(rc))
/* Stderr. */
if (RT_SUCCESS(rc))
/* IPC notification pipe. */
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
rc = RTPollSetAddPipe(hPollSet, pThread->hNotificationPipeR, RTPOLL_EVT_READ, VBOXSERVICECTRLPIPEID_IPC_NOTIFY);
if (RT_SUCCESS(rc))
{
rc = VBoxServiceControlThreadCreateProcess(pThread->pszCmd, pThread->papszArgs, hEnv, pThread->uFlags,
&hProcess);
if (RT_FAILURE(rc))
/*
* Tell the control thread that it can continue
* spawning services. This needs to be done after the new
* process has been started because otherwise signal handling
* on (Open) Solaris does not work correctly (see #5068).
*/
if (RT_SUCCESS(rc))
fSignalled = true;
if (RT_SUCCESS(rc))
{
/*
* Close the child ends of any pipes and redirected files.
*/
/* Enter the process loop. */
/*
* The handles that are no longer in the set have
* been closed by the above call in order to prevent
* the guest from getting stuck accessing them.
* So, NIL the handles to avoid closing them again.
*/
{
}
}
}
}
if (phStdErr)
}
if (phStdOut)
}
}
}
}
/* Move thread to stopped thread list. */
{
if (RT_FAILURE(rc))
{
if (RT_FAILURE(rc2))
VBoxServiceError("ControlThread: Could not report process failure error; rc=%Rrc (process error %Rrc)\n",
}
if (RT_FAILURE(rc2))
{
VBoxServiceError("ControlThread: [PID %u]: Cancelling pending host requests failed; rc=%Rrc\n",
if (RT_SUCCESS(rc))
}
/* Disconnect from guest control service. */
}
/*
* If something went wrong signal the user event so that others don't wait
* forever on this thread.
*/
return rc;
}
/**
* Thread main routine for a started process.
*
* @return IPRT status code.
* @param RTTHREAD Pointer to the thread's data.
* @param void* User-supplied argument pointer.
*
*/
{
}
/**
* Executes (starts) a process on the guest. This causes a new thread to be created
* so that this function will not block the overall program execution.
*
* @return IPRT status code.
* @param uContextID Context ID to associate the process to start with.
* @param pProcess Process info.
*/
{
/*
* Allocate new thread data and assign it to our thread list.
*/
if (!pThread)
return VERR_NO_MEMORY;
if (RT_SUCCESS(rc))
{
static uint32_t s_uCtrlExecThread = 0;
if (s_uCtrlExecThread++ == UINT32_MAX)
s_uCtrlExecThread = 0; /* Wrap around to not let IPRT freak out. */
if (RT_FAILURE(rc))
{
VBoxServiceError("ControlThread: RTThreadCreate failed, rc=%Rrc\n, pThread=%p\n",
}
else
{
/* Wait for the thread to initialize. */
|| RT_FAILURE(rc))
{
VBoxServiceError("ControlThread: Thread for process \"%s\" failed to start, rc=%Rrc\n",
}
else
{
}
}
}
if (RT_FAILURE(rc))
return rc;
}
/**
* Performs a request to a specific (formerly started) guest process and waits
* for its response.
*
* @return IPRT status code.
* @param uPID PID of guest process to perform a request to.
* @param pRequest Pointer to request to perform.
*/
{
/* Rest in pRequest is optional (based on the request type). */
int rc = VINF_SUCCESS;
if (pThread)
{
{
rc = VERR_CANCELLED;
}
else
{
/* Set request structure pointer. */
/** @todo To speed up simultaneous guest process handling we could add a worker threads
* or queue in order to wait for the request to happen. Later. */
/* Wake up guest thrad by sending a wakeup byte to the notification pipe so
* that RTPoll unblocks (returns) and we then can do our requested operation. */
if (RT_SUCCESS(rc))
if ( RT_SUCCESS(rc)
&& cbWritten)
{
VBoxServiceVerbose(3, "ControlThread: [PID %u]: Waiting for response on enmType=%u, pvData=0x%p, cbData=%u\n",
}
}
}
else /* PID not found! */
rc = VERR_NOT_FOUND;
VBoxServiceVerbose(3, "ControlThread: [PID %u]: Performed enmType=%u, uCID=%u, pvData=0x%p, cbData=%u, rc=%Rrc\n",
return rc;
}