VBoxServiceControlSession.cpp revision 9bff17fe6983cfda2ddd98f1979841bcb48e78e7
/* $Id$ */
/** @file
* VBoxServiceControlSession - Guest session handling. Also handles
* the forked session processes.
*/
/*
* Copyright (C) 2013 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 "VBoxServiceInternal.h"
#include "VBoxServiceUtils.h"
#include "VBoxServiceControl.h"
using namespace guestControl;
/*******************************************************************************
* Externals *
*******************************************************************************/
extern VBOXSERVICECTRLSESSION g_Session;
extern int VBoxServiceLogCreate(const char *pszLogFile);
extern void VBoxServiceLogDestroy(void);
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static PVBOXSERVICECTRLFILE gstcntlSessionGetFile(const PVBOXSERVICECTRLSESSION pSession, uint32_t uHandle);
static int gstcntlSessionGetOutput(const PVBOXSERVICECTRLSESSION pSession, uint32_t uPID, uint32_t uCID, uint32_t uHandleId, uint32_t cMsTimeout, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
static int gstcntlSessionHandleFileOpen(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLHOSTCTX pHostCtx);
static int gstcntlSessionHandleFileClose(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLHOSTCTX pHostCtx);
static int gstcntlSessionHandleFileRead(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLHOSTCTX pHostCtx);
static int gstcntlSessionHandleFileWrite(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLHOSTCTX pHostCtx, void *pvScratchBuf, size_t cbScratchBuf);
static int gstcntlSessionHandleFileSeek(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLHOSTCTX pHostCtx);
static int gstcntlSessionHandleFileTell(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLHOSTCTX pHostCtx);
static int gstcntlSessionSetInput(const PVBOXSERVICECTRLSESSION pSession, uint32_t uPID, uint32_t uCID, bool fPendingClose, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
/** Generic option indices for session fork arguments. */
enum
{
VBOXSERVICESESSIONOPT_LOG_FILE = 1000,
};
{
if (RT_SUCCESS(rc))
{
/* Remove file entry in any case. */
/* Destroy this object. */
}
return rc;
}
{
/** @todo Use a map later! */
{
return pFileCur;
}
return NULL;
}
#ifdef DEBUG
{
if (!cbBuf)
return VINF_SUCCESS;
char szFile[RTPATH_MAX];
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
}
}
return rc;
}
#endif
{
char szFile[RTPATH_MAX];
char szOpenMode[64];
char szDisposition[64];
uint32_t uCreationMode = 0;
/* File to open. */
/* Open mode. */
szOpenMode, sizeof(szOpenMode),
/* Disposition. */
szDisposition, sizeof(szDisposition),
/* Creation mode. */
/* Offset. */
&uOffset);
if (RT_SUCCESS(rc))
{
if (pFile)
{
if (RT_SUCCESS(rc))
{
if ( RT_SUCCESS(rc)
&& uOffset)
{
/* Seeking is optional. */
if (RT_FAILURE(rc2))
}
else
}
if (RT_SUCCESS(rc))
{
}
if (RT_FAILURE(rc))
}
else
rc = VERR_NO_MEMORY;
/* Report back in any case. */
if (RT_FAILURE(rc2))
VBoxServiceError("[File %s]: Failed to report file open status, rc=%Rrc\n",
if (RT_SUCCESS(rc))
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
if (pFile)
{
}
else
rc = VERR_NOT_FOUND;
/* Report back in any case. */
if (RT_FAILURE(rc2))
if (RT_SUCCESS(rc))
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
void *pvDataRead = pvScratchBuf;
if (pFile)
{
if (cbToRead)
{
if (cbToRead > cbScratchBuf)
{
if (!pvDataRead)
rc = VERR_NO_MEMORY;
}
}
else
}
else
rc = VERR_NOT_FOUND;
/* Report back in any case. */
if ( cbToRead > cbScratchBuf
&& pvDataRead)
if (RT_FAILURE(rc2))
if (RT_SUCCESS(rc))
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
void *pvDataRead = pvScratchBuf;
if (pFile)
{
if (cbToRead)
{
if (cbToRead > cbScratchBuf)
{
if (!pvDataRead)
rc = VERR_NO_MEMORY;
}
}
else
}
else
rc = VERR_NOT_FOUND;
/* Report back in any case. */
if ( cbToRead > cbScratchBuf
&& pvDataRead)
if (RT_FAILURE(rc2))
if (RT_SUCCESS(rc))
}
return rc;
}
{
&cbToWrite);
if (RT_SUCCESS(rc))
{
if (pFile)
{
}
else
rc = VERR_NOT_FOUND;
/* Report back in any case. */
if (RT_FAILURE(rc2))
if (RT_SUCCESS(rc))
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
if (pFile)
{
}
else
rc = VERR_NOT_FOUND;
/* Report back in any case. */
if (RT_FAILURE(rc2))
if (RT_SUCCESS(rc))
}
return rc;
}
{
uint64_t uOffsetActual = 0;
&uSeekMethod, &uOffset);
if (RT_SUCCESS(rc))
{
if (pFile)
{
unsigned uSeekMethodIPRT;
switch (uSeekMethod)
{
break;
break;
case GUEST_FILE_SEEKTYPE_END:
break;
default:
break;
}
if (RT_SUCCESS(rc))
}
else
rc = VERR_NOT_FOUND;
/* Report back in any case. */
if (RT_FAILURE(rc2))
if (RT_SUCCESS(rc))
}
return rc;
}
{
uint64_t uOffsetActual = 0;
if (RT_SUCCESS(rc))
{
if (pFile)
{
}
else
rc = VERR_NOT_FOUND;
/* Report back in any case. */
if (RT_FAILURE(rc2))
if (RT_SUCCESS(rc))
}
return rc;
}
/**
* Handles starting a guest processes.
*
* @returns IPRT status code.
* @param pSession Guest session.
* @param pHostCtx Host context.
*/
{
int rc;
bool fStartAllowed = false; /* Flag indicating whether starting a process is allowed or not. */
)
{
/* Initialize maximum environment block size -- needed as input
* parameter to retrieve the stuff from the host. On output this then
* will contain the actual block size. */
/* Command */
/* Flags */
/* Arguments */
/* Environment */
/* Credentials; for hosts with VBox < 4.3 (protocol version 1).
* For protocl v2 and up the credentials are part of the session
* opening call. */
/* Timeout (in ms) */
/* Process priority */
/* Process affinity */
if (RT_SUCCESS(rc))
{
VBoxServiceVerbose(3, "Request to start process szCmd=%s, uFlags=0x%x, szArgs=%s, szEnv=%s, szUser=%s, szPassword=%s, uTimeout=%RU32\n",
#ifdef DEBUG
#else
"XXX", /* Never show passwords in release mode. */
#endif
if (RT_FAILURE(rc))
/* Keep going. */
if (RT_SUCCESS(rc))
{
if (fStartAllowed)
{
}
else
}
}
}
else
/* In case of an error we need to notify the host to not wait forever for our response. */
if (RT_FAILURE(rc))
{
VBoxServiceError("Starting process failed with rc=%Rrc, protocol=%RU32, parameters=%RU32\n",
/*
* Note: The context ID can be 0 because we mabye weren't able to fetch the command
* from the host. The host in case has to deal with that!
*/
0 /* PID, invalid */,
if (RT_FAILURE(rc2))
{
if (RT_SUCCESS(rc))
}
}
return rc;
}
/**
* Handles input for a started process by copying the received data into its
* stdin pipe.
*
* @returns IPRT status code.
* @param pvScratchBuf The scratch buffer.
* @param cbScratchBuf The scratch buffer size for retrieving the input data.
*/
{
/*
* Ask the host for the input data.
*/
if (RT_FAILURE(rc))
{
VBoxServiceError("[PID %RU32]: Failed to retrieve exec input command! Error: %Rrc\n",
}
else if (cbSize > cbScratchBuf)
{
VBoxServiceError("[PID %RU32]: Too much input received! cbSize=%u, cbScratchBuf=%u\n",
}
else
{
/*
* Is this the last input block we need to deliver? Then let the pipe know ...
*/
bool fPendingClose = false;
if (uFlags & INPUT_FLAG_EOF)
{
fPendingClose = true;
}
VBoxServiceVerbose(4, "[PID %RU32]: Written input, CID=%u, rc=%Rrc, uFlags=0x%x, fPendingClose=%d, cbSize=%u, cbWritten=%u\n",
if (RT_SUCCESS(rc))
{
uFlags = 0; /* No flags at the moment. */
}
else
{
if (rc == VERR_BAD_PIPE)
else if (rc == VERR_BUFFER_OVERFLOW)
}
}
/*
* If there was an error and we did not set the host status
* yet, then do it now.
*/
if ( RT_FAILURE(rc)
&& uStatus == INPUT_STS_UNDEFINED)
{
}
VBoxServiceVerbose(3, "[PID %RU32]: Input processed, CID=%u, uStatus=%u, uFlags=0x%x, cbWritten=%u\n",
/* Note: Since the context ID is unique the request *has* to be completed here,
* regardless whether we got data or not! Otherwise the progress object
* on the host never will get completed! */
if (RT_FAILURE(rc))
VBoxServiceError("[PID %RU32]: Failed to report input status! Error: %Rrc\n",
return rc;
}
/**
* Handles the guest control output command.
*
* @return IPRT status code.
*/
{
if (RT_SUCCESS(rc))
{
if (pBuf)
{
VBoxServiceVerbose(3, "[PID %RU32]: Got output, rc=%Rrc, CID=%u, cbRead=%u, uHandle=%u, uFlags=%u\n",
#ifdef DEBUG
&& (uHandleID == OUTPUT_HANDLE_ID_STDERR))
{
char szDumpFile[RTPATH_MAX];
if (RT_SUCCESS(rc))
}
&& ( uHandleID == OUTPUT_HANDLE_ID_STDOUT
{
char szDumpFile[RTPATH_MAX];
if (RT_SUCCESS(rc))
}
#endif
* data which the host needs to work with -- so just pass through all data unfiltered! */
/* Note: Since the context ID is unique the request *has* to be completed here,
* regardless whether we got data or not! Otherwise the progress object
* on the host never will get completed! */
int rc2 = VbglR3GuestCtrlProcCbOutput(pHostCtx->uClientID, pHostCtx->uContextID, uPID, uHandleID, uFlags,
if (RT_SUCCESS(rc))
rc = VINF_SUCCESS;
}
else
rc = VERR_NO_MEMORY;
}
if (RT_FAILURE(rc))
VBoxServiceError("[PID %RU32]: Error handling output command! Error: %Rrc\n",
return rc;
}
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (pProcess)
{
}
else
rc = VERR_NOT_FOUND;
}
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (pProcess)
{
}
else
rc = VERR_NOT_FOUND;
}
}
return rc;
}
volatile bool *pfShutdown)
{
int rc = VINF_SUCCESS;
/* Only anonymous sessions (that is, sessions which run with local
* service privileges) or forked session processes can do certain
* operations. */
switch (uMsg)
{
/* Fall thru is intentional. */
case HOST_SESSION_CLOSE:
/* Shutdown this fork. */
*pfShutdown = true; /* Shutdown in any case. */
break;
case HOST_EXEC_CMD:
break;
case HOST_EXEC_SET_INPUT:
break;
case HOST_EXEC_GET_OUTPUT:
break;
case HOST_EXEC_TERMINATE:
break;
case HOST_EXEC_WAIT_FOR:
break;
case HOST_FILE_OPEN:
break;
case HOST_FILE_CLOSE:
break;
case HOST_FILE_READ:
break;
case HOST_FILE_READ_AT:
break;
case HOST_FILE_WRITE:
break;
case HOST_FILE_WRITE_AT:
break;
case HOST_FILE_SEEK:
break;
case HOST_FILE_TELL:
break;
default:
/* Don't terminate here; just wait for the next message. */
break;
}
return rc;
}
/**
* Thread main routine for a forked guest session. This
* thread runs in the main executable to control the forked
* session process.
*
* @return IPRT status code.
* @param RTTHREAD Pointer to the thread's data.
* @param void* User-supplied argument pointer.
*
*/
{
if (RT_SUCCESS(rc))
{
}
else
/* Let caller know that we're done initializing. */
if (RT_SUCCESS(rc))
bool fProcessAlive = true;
if (RT_SUCCESS(rc))
{
uint64_t u64TimeoutStart = 0;
int rcWait;
for (;;)
{
continue;
else if ( rcWait == VINF_SUCCESS
|| rcWait == VERR_PROCESS_NOT_FOUND)
{
fProcessAlive = false;
break;
}
else
("Got unexpected rc=%Rrc while waiting for session process termination\n", rcWait));
{
if (!u64TimeoutStart)
{
VBoxServiceVerbose(3, "Guest session ID=%RU32 thread was asked to terminate, waiting for session process to exit ...\n",
}
{
break;
}
}
}
if (!fProcessAlive)
{
VBoxServiceVerbose(2, "Guest session ID=%RU32 process terminated with rc=%Rrc, reason=%ld, status=%d\n",
}
}
if (fProcessAlive)
{
for (int i = 0; i < 3; i++)
{
uSessionID, i + 1);
if (RT_SUCCESS(rc))
break;
RTThreadSleep(3000);
}
uSessionID, rc);
}
else
{
switch (ProcessStatus.enmReason)
{
case RTPROCEXITREASON_NORMAL:
break;
case RTPROCEXITREASON_ABEND:
break;
case RTPROCEXITREASON_SIGNAL:
break;
default:
AssertMsgFailed(("Unhandled process termination reason (%ld)",
break;
}
}
VBoxServiceVerbose(3, "Guest session ID=%RU32 thread ended with sessionStatus=%ld, sessionRc=%Rrc\n",
/* Report final status. */
if (RT_FAILURE(rc2))
VBoxServiceError("Reporting session ID=%RU32 final status failed with rc=%Rrc\n",
uSessionID, rc2);
uSessionID, rc);
return rc;
}
{
bool fSessionFilter = true;
VBoxServiceVerbose(0, "Hi, this is guest session ID=%RU32\n",
if (RT_SUCCESS(rc))
{
/* Set session filter. */
uFilterAdd, rc);
if ( RT_FAILURE(rc)
&& rc == VERR_NOT_SUPPORTED)
{
/* No session filter available. Skip. */
fSessionFilter = false;
rc = VINF_SUCCESS;
}
}
else
/* Report started status. */
if (RT_FAILURE(rc2))
VBoxServiceError("Reporting session ID=%RU32 started status failed with rc=%Rrc\n",
/* Allocate a scratch buffer for commands which also send
* payload data with them. */
if (RT_SUCCESS(rc))
{
if (!pvScratchBuf)
rc = VERR_NO_MEMORY;
}
if (RT_SUCCESS(rc))
{
bool fShutdown = false;
for (;;)
{
if (rc == VERR_TOO_MUCH_DATA)
{
VBoxServiceVerbose(4, "Message requires %RU32 parameters, but only 2 supplied -- retrying request (no error!)...\n", cParms);
}
else if (RT_FAILURE(rc))
VBoxServiceVerbose(3, "Getting host message failed with %Rrc\n", rc); /* VERR_GEN_IO_FAILURE seems to be normal if ran into timeout. */
if (RT_SUCCESS(rc))
{
/* Set number of parameters for current host context. */
/* ... and pass it on to the session handler. */
}
if (fShutdown)
break;
/* Let's sleep for a bit and let others run ... */
}
}
if (pvScratchBuf)
}
/**
* Finds a (formerly) started guest process given by its PID and locks it.
* Must be unlocked by the caller with GstCntlProcessRelease().
*
* @return PVBOXSERVICECTRLTHREAD Locked guest process if found, otherwise NULL.
* @param PVBOXSERVICECTRLSESSION Pointer to guest session where to search process in.
* @param uPID PID to search for.
*/
PVBOXSERVICECTRLPROCESS GstCntlSessionAcquireProcess(PVBOXSERVICECTRLSESSION pSession, uint32_t uPID)
{
if (RT_SUCCESS(rc))
{
{
{
if (RT_SUCCESS(rc))
break;
}
}
if (RT_SUCCESS(rc))
}
return pThread;
}
{
VBoxServiceVerbose(0, "Session %RU32 is about to close ...\n",
/*
* Close all guest processes.
*/
/* Signal all guest processes in the active list that we want to shutdown. */
/* Wait for all active threads to shutdown and destroy the active thread list. */
while (pProcess)
{
30 * 1000 /* Wait 30 seconds max. */,
NULL /* rc */);
if (RT_FAILURE(rc2))
{
/* Keep going. */
}
if (fLast)
break;
}
if (RT_FAILURE(rc))
("Guest process active thread list still contains entries when it should not\n"));
("Guest process inactive thread list still contains entries when it should not\n"));
/*
* Close all left guest files.
*/
while (pFile)
{
if (RT_FAILURE(rc2))
{
VBoxServiceError("Unable to close file \"%s\"; rc=%Rrc\n",
/* Keep going. */
}
if (fLast)
break;
}
("Guest file list still contains entries when it should not\n"));
return rc;
}
{
/* Destroy critical section. */
return rc;
}
/**
*
* @return IPRT status code.
* @param pSession Guest session.
* @param uPID PID of process to retrieve the output from.
* @param uCID Context ID.
* @param uHandleId Stream ID (stdout = 0, stderr = 2) to get the output from.
* @param cMsTimeout Timeout (in ms) to wait for output becoming
* available.
* @param pvBuf Pointer to a pre-allocated buffer to store the output.
* @param cbBuf Size (in bytes) of the pre-allocated buffer.
* @param pcbRead Pointer to number of bytes read. Optional.
*/
{
int rc = VINF_SUCCESS;
VBOXSERVICECTRLREQUESTTYPE reqType = VBOXSERVICECTRLREQUEST_UNKNOWN; /* (gcc maybe, well, wrong.) */
switch (uHandleId)
{
case OUTPUT_HANDLE_ID_STDERR:
break;
case OUTPUT_HANDLE_ID_STDOUT:
break;
default:
break;
}
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (pProcess)
{
}
else
rc = VERR_NOT_FOUND;
}
}
return rc;
}
{
{
/* Protocol must be specified explicitly. */
/* Session ID must be specified explicitly. */
}
/* Init critical section for protecting the thread lists. */
return rc;
}
/**
* Sets the specified guest thread to a certain list.
** @todo Still needed?
*
* @return IPRT status code.
* @param pSession Guest session.
* @param enmList List to move thread to.
* @param pProcess Guest process to set.
*/
{
if (RT_SUCCESS(rc))
{
switch (enmList)
{
break;
break;
default:
break;
}
if (!pAnchor)
if (RT_SUCCESS(rc))
{
{
/* If thread was assigned to a list before,
* remove the thread from the old list first. */
}
/* Add thread to desired list. */
}
if (RT_SUCCESS(rc))
}
return VINF_SUCCESS;
}
/**
* Determines whether starting a new guest process according to the
* maximum number of concurrent guest processes defined is allowed or not.
*
* @return IPRT status code.
* @param pbAllowed True if starting (another) guest process
* is allowed, false if not.
*/
bool *pbAllowed)
{
if (RT_SUCCESS(rc))
{
/*
* Check if we're respecting our memory policy by checking
* how many guest processes are started and served already.
*/
bool fLimitReached = false;
{
uint32_t uProcsRunning = 0;
if (iProcsLeft < 0)
{
fLimitReached = true;
}
}
*pbAllowed = !fLimitReached;
if (RT_SUCCESS(rc))
}
return rc;
}
/**
* Reaps all inactive guest process threads.
*
* @return IPRT status code.
*/
{
if (RT_SUCCESS(rc))
{
while (pThread)
{
NULL /* rc */);
if (RT_SUCCESS(rc2))
{
if (RT_FAILURE(rc2))
{
}
}
else
/* Keep going. */
if (fLast)
break;
}
if (RT_SUCCESS(rc))
}
return rc;
}
/**
* Injects input to a specified running guest process.
*
* @return IPRT status code.
* @param pSession Guest session.
* @param uPID PID of process to set the input for.
* @param uCID Context ID to use for reporting back.
* @param fPendingClose Flag indicating whether this is the last input block sent to the process.
* @param pvBuf Pointer to a buffer containing the actual input data.
* @param cbBuf Size (in bytes) of the input buffer data.
* @param pcbWritten Pointer to number of bytes written to the process. Optional.
*/
bool fPendingClose,
{
/* pvBuf is optional. */
/* cbBuf is optional. */
/* pcbWritten is optional. */
if (RT_SUCCESS(rc))
{
if (pProcess)
{
}
else
rc = VERR_NOT_FOUND;
if (RT_SUCCESS(rc))
{
if (pcbWritten)
}
}
return rc;
}
/**
* Creates a guest session. This will spawn a new VBoxService.exe instance under
* behalf of the given user which then will act as a session host. On successful
* open, the session will be added to the given session thread list.
*
* @return IPRT status code.
* @param pList Which list to use to store the session thread in.
* @param pSessionStartupInfo Session startup info.
* @param ppSessionThread Returns newly created session thread on success.
* Optional.
*/
{
/* ppSessionThread is optional. */
#ifdef DEBUG
/* Check for existing session in debug mode. Should never happen because of
* Main consistency. */
{
{
AssertMsgFailed(("Guest session %RU32 (%p) already exists when it should not",
return VERR_ALREADY_EXISTS;
}
}
#endif
int rc = VINF_SUCCESS;
PVBOXSERVICECTRLSESSIONTHREAD pSession = (PVBOXSERVICECTRLSESSIONTHREAD)RTMemAllocZ(sizeof(VBOXSERVICECTRLSESSIONTHREAD));
if (pSession)
{
/* Copy over session startup info. */
/* Is this an anonymous session? */
/* Anonymous sessions run with the same privileges as the main VBoxService executable. */
if (fAnonymous)
{
VBoxServiceVerbose(3, "New anonymous guest session ID=%RU32 created, uFlags=%x, using protocol %RU32\n",
}
else
{
VBoxServiceVerbose(3, "Forking new guest session ID=%RU32, szUser=%s, szPassword=%s, szDomain=%s, uFlags=%x, using protocol %RU32\n",
#ifdef DEBUG
#else
"XXX", /* Never show passwords in release mode. */
#endif
}
/* Fork child doing the actual session handling. */
char szExeName[RTPATH_MAX];
if (pszExeName)
{
if (!fAnonymous)
{
if (!RTStrPrintf(szParmUserName, sizeof(szParmUserName), "--username=%s", pSession->StartupInfo.szUser))
}
char szParmSessionID[32];
{
}
char szParmSessionProto[32];
if (RT_SUCCESS(rc) && !RTStrPrintf(szParmSessionProto, sizeof(szParmSessionProto), "--session-proto=%RU32",
{
}
if (RT_SUCCESS(rc))
{
int iOptIdx = 0; /* Current index in argument vector. */
char const *papszArgs[8];
if (!fAnonymous)
/* Add same verbose flags as parent process. */
int rc2 = VINF_SUCCESS;
char szParmVerbose[32] = { 0 };
{
if (i == 0)
if (RT_FAILURE(rc2))
break;
}
if (RT_SUCCESS(rc2))
/* Add log file handling. Each session will have an own
* log file, naming based on the parent log file. */
char szParmLogFile[RTPATH_MAX];
if ( RT_SUCCESS(rc2)
&& strlen(g_szLogFile))
{
if (pszLogFile)
{
if (RTPathHasExt(pszLogFile))
char *pszLogSuffix;
pSessionStartupInfo->szUser) < 0)
{
}
else
{
if (RT_SUCCESS(rc2))
{
"--logfile=%s", pszLogFile))
{
}
}
}
if (RT_FAILURE(rc2))
VBoxServiceError("Error building session logfile string for session %RU32 (user %s), rc=%Rrc\n",
if (pszLogExt)
}
if (RT_SUCCESS(rc2))
}
else
if (g_cVerbosity > 3)
{
iOptIdx = 0;
}
| RTPROC_FLAGS_HIDDEN; /** @todo More flags from startup info? */
#if 0 /* Pipe handling not needed (yet). */
/* Setup pipes. */
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
}
if (RT_SUCCESS(rc))
{
/* Fork the thing. */
/** @todo Do we need a custom environment block? */
}
if (RT_SUCCESS(rc))
{
/*
* Close the child ends of any pipes and redirected files.
*/
}
}
}
#else
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
}
}
#endif
}
}
else
if (RT_SUCCESS(rc))
{
/* Start session thread. */
static uint32_t s_uCtrlSessionThread = 0;
if (s_uCtrlSessionThread++ == UINT32_MAX)
s_uCtrlSessionThread = 0; /* Wrap around to not let IPRT freak out. */
if (RT_FAILURE(rc))
{
}
else
{
/* Wait for the thread to initialize. */
|| RT_FAILURE(rc))
{
VBoxServiceError("Thread for session ID=%RU32 failed to start, rc=%Rrc\n",
if (RT_SUCCESS(rc))
}
else
{
/* Add session to list. */
if (ppSessionThread) /* Return session if wanted. */
}
}
}
if (RT_FAILURE(rc))
{
}
}
else
rc = VERR_NO_MEMORY;
return rc;
}
/**
* Closes a formerly opened guest session and removes it from
* the session list.
*
* @return IPRT status code.
* @param pThread Guest session thread to close.
* @param uFlags Closing flags.
*/
{
/** @todo Validate closing flags. */
{
AssertMsgFailed(("Guest session thread of session %p does not exist when it should",
pThread));
return VERR_NOT_FOUND;
}
int rc = VINF_SUCCESS;
/* The fork should have received the same closing request,
* so just wait 30s for the process to close. On timeout kill
* it in a not so gentle manner. */
{
/* Ask the thread to shutdown. */
int rcThread;
if (RT_FAILURE(rc))
{
VBoxServiceError("Waiting for session thread ID=%RU32 to close failed with rc=%Rrc\n",
}
else
/* Remove session from list and destroy object. */
if (RT_FAILURE(rc))
VBoxServiceError("Closing session ID=%RU32 failed with rc=%Rrc\n",
}
return rc;
}
/**
* Close all formerly opened guest session threads.
*
* @return IPRT status code.
* @param pList Which list to close the session threads for.
* @param uFlags Closing flags.
*/
{
int rc = VINF_SUCCESS;
while (pSessionCur)
{
if (RT_SUCCESS(rc))
{
/* Keep going. */
}
if (fLast)
break;
}
return rc;
}
{
static const RTGETOPTDEF s_aOptions[] =
{
};
int ch;
/* Init the session object. */
if (RT_FAILURE(rc))
&& RT_SUCCESS(rc))
{
/* For options that require an argument, ValueUnion has received the value. */
switch (ch)
{
break;
/** @todo. */
break;
break;
break;
/** @todo Implement help? */
case 'v':
g_cVerbosity++;
break;
case VINF_GETOPT_NOT_OPTION:
/* Ignore; might be "guestsession" main command. */
break;
default:
break; /* Never reached. */
}
}
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
return rcExit;
}