VBoxServiceControl.cpp revision e06a7c97712c2fb5d6a55a2b80e774913ed91d1a
/* $Id$ */
/** @file
* VBoxServiceControl - Host-driven Guest Control.
*/
/*
* Copyright (C) 2010 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/semaphore.h>
#include <VBox/VBoxGuestLib.h>
#include "VBoxServiceInternal.h"
#include "VBoxServiceUtils.h"
using namespace guestControl;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The control interval (millseconds). */
/** The semaphore we're blocking on. */
/** The guest property service client ID. */
static uint32_t g_GuestControlSvcClientID = 0;
/** List of spawned processes */
/** @copydoc VBOXSERVICE::pfnPreInit */
static DECLCALLBACK(int) VBoxServiceControlPreInit(void)
{
return VINF_SUCCESS;
}
/** @copydoc VBOXSERVICE::pfnOption */
static DECLCALLBACK(int) VBoxServiceControlOption(const char **ppszShort, int argc, char **argv, int *pi)
{
int rc = -1;
if (ppszShort)
/* no short options */;
return rc;
}
/** @copydoc VBOXSERVICE::pfnInit */
static DECLCALLBACK(int) VBoxServiceControlInit(void)
{
/*
* If not specified, find the right interval default.
* Then create the event sem to block on.
*/
if (!g_ControlInterval)
g_ControlInterval = 1000;
if (RT_SUCCESS(rc))
else
{
}
/* Init thread list. */
return rc;
}
{
char szUser[128];
char szPassword[128];
if (uNumParms != 14)
return VERR_INVALID_PARAMETER;
/* Command */
/* Flags */
&uFlags,
/* Arguments */
/* Environment */
/* Pipes */
/* Credentials */
szPassword, sizeof(szPassword),
/* Timelimit */
&uTimeLimitMS);
if (RT_FAILURE(rc))
{
}
else
{
}
return rc;
}
{
if (RT_FAILURE(rc))
{
}
else
{
/* Let's have a look if we have a running process with PID = uPID ... */
bool bFound = false;
{
{
{
bFound = true;
break;
}
}
}
if (bFound)
{
if (pBuf)
{
if (RT_SUCCESS(rc))
{
/* cbRead now contains actual size. */
}
}
else
rc = VERR_NO_MEMORY;
}
else
}
return rc;
}
/** @copydoc VBOXSERVICE::pfnWorker */
{
/*
* Tell the control thread that it can continue
* spawning services.
*/
int rc = VINF_SUCCESS;
/*
* Execution loop.
*
* @todo
*/
for (;;)
{
rc = VbglR3GuestCtrlGetHostMsg(g_GuestControlSvcClientID, &uMsg, &uNumParms, 1000 /* 1s timeout */);
if (rc == VERR_TOO_MUCH_DATA)
{
VBoxServiceVerbose(3, "Control: Message requires %ld parameters, but only 2 supplied -- retrying request ...\n", uNumParms);
rc = VINF_SUCCESS;
}
else if (rc == VERR_TIMEOUT)
{
RTThreadSleep(100);
}
if (RT_SUCCESS(rc))
{
switch(uMsg)
{
break;
break;
default:
/* Don't terminate here; just wait for the next message. */
break;
}
if (RT_FAILURE(rc))
}
/*
* Block for a while.
*
* The event semaphore takes care of ignoring interruptions and it
* allows us to implement service wakeup later.
*/
if (*pfShutdown)
{
rc = 0;
break;
}
if (*pfShutdown)
{
rc = 0;
break;
}
{
break;
}
}
return rc;
}
/** @copydoc VBOXSERVICE::pfnStop */
static DECLCALLBACK(void) VBoxServiceControlStop(void)
{
/** @todo Later, figure what to do if we're in RTProcWait(). it's a very
* annoying call since doesn't support timeouts in the posix world. */
}
/** @copydoc VBOXSERVICE::pfnTerm */
static DECLCALLBACK(void) VBoxServiceControlTerm(void)
{
/* Signal all threads that we want to shutdown. */
/* Wait for threads to shutdown. */
{
{
if (RT_FAILURE(rc2))
}
/* Destroy thread specific data. */
{
break;
default:
break;
}
}
/* Finally destroy thread list. */
while (pNode)
{
break;
}
if (g_hControlEvent != NIL_RTSEMEVENTMULTI)
{
}
}
/**
* The 'vminfo' service description.
*/
{
/* pszName. */
"control",
/* pszDescription. */
"Host-driven Guest Control",
/* pszUsage. */
"[--control-interval <ms>]"
,
/* pszOptions. */
" --control-interval Specifies the interval at which to check for\n"
" new ocntrol commands. The default is 1000 ms.\n"
,
/* methods */
};