summaryrefslogtreecommitdiff
path: root/src/VBox/Additions/common/VBoxService/VBoxService.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2014-03-26 19:21:20 +0000
committer <>2014-05-08 15:03:54 +0000
commitfb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch)
treec2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Additions/common/VBoxService/VBoxService.cpp
parent58ed4748338f9466599adfc8a9171280ed99e23f (diff)
downloadVirtualBox-master.tar.gz
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/Additions/common/VBoxService/VBoxService.cpp')
-rw-r--r--src/VBox/Additions/common/VBoxService/VBoxService.cpp64
1 files changed, 49 insertions, 15 deletions
diff --git a/src/VBox/Additions/common/VBoxService/VBoxService.cpp b/src/VBox/Additions/common/VBoxService/VBoxService.cpp
index 639b97f7..8ce44dae 100644
--- a/src/VBox/Additions/common/VBoxService/VBoxService.cpp
+++ b/src/VBox/Additions/common/VBoxService/VBoxService.cpp
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (C) 2007-2011 Oracle Corporation
+ * Copyright (C) 2007-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;
@@ -56,6 +56,9 @@
#include <VBox/log.h>
#include "VBoxServiceInternal.h"
+#ifdef VBOX_WITH_GUEST_CONTROL
+# include "VBoxServiceControl.h"
+#endif
/*******************************************************************************
@@ -65,6 +68,7 @@
char *g_pszProgName = (char *)"";
/** The current verbosity level. */
int g_cVerbosity = 0;
+char g_szLogFile[RTPATH_MAX + 128] = "";
/** Logging parameters. */
/** @todo Make this configurable later. */
static PRTLOGGER g_pLoggerRelease = NULL;
@@ -126,7 +130,7 @@ static struct
# endif
{ &g_VMStatistics, NIL_RTTHREAD, false, false, false, false, true },
#endif
-#if defined(VBOX_WITH_PAGE_SHARING) && defined(RT_OS_WINDOWS)
+#if defined(VBOXSERVICE_PAGE_SHARING)
{ &g_PageSharing, NIL_RTTHREAD, false, false, false, false, true },
#endif
#ifdef VBOX_WITH_SHARED_FOLDERS
@@ -211,11 +215,12 @@ static void VBoxServiceLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmP
/**
* Creates the default release logger outputting to the specified file.
+ * Pass NULL for disabled logging.
*
* @return IPRT status code.
* @param pszLogFile Filename for log output. Optional.
*/
-static int VBoxServiceLogCreate(const char *pszLogFile)
+int VBoxServiceLogCreate(const char *pszLogFile)
{
/* Create release logger (stdout + file). */
static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
@@ -241,7 +246,8 @@ static int VBoxServiceLogCreate(const char *pszLogFile)
return rc;
}
-static void VBoxServiceLogDestroy(void)
+
+void VBoxServiceLogDestroy(void)
{
RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
}
@@ -633,6 +639,8 @@ int VBoxServiceStopServices(void)
g_aServices[j].pDesc->pfnStop();
}
+ VBoxServiceVerbose(3, "All stop functions for services called\n");
+
/*
* Wait for all the service threads to complete.
*/
@@ -745,6 +753,7 @@ void VBoxServiceMainWait(void)
int main(int argc, char **argv)
{
RTEXITCODE rcExit;
+ bool fUserSession = false;
/*
* Init globals and such.
@@ -769,14 +778,32 @@ int main(int argc, char **argv)
return rcExit;
#endif
+#ifdef VBOX_WITH_GUEST_CONTROL
+ /*
+ * Check if we're the specially spawned VBoxService.exe process that
+ * handles a guest control session.
+ */
+ if ( argc >= 2
+ && !RTStrICmp(argv[1], "guestsession"))
+ fUserSession = true;
+#endif
+
/*
* Connect to the kernel part before daemonizing so we can fail and
* complain if there is some kind of problem. We need to initialize the
* guest lib *before* we do the pre-init just in case one of services needs
* do to some initial stuff with it.
*/
- VBoxServiceVerbose(2, "Calling VbgR3Init()\n");
- rc = VbglR3Init();
+ if (fUserSession)
+ {
+ VBoxServiceVerbose(2, "Calling VbgR3InitUser()\n");
+ rc = VbglR3InitUser();
+ }
+ else
+ {
+ VBoxServiceVerbose(2, "Calling VbgR3Init()\n");
+ rc = VbglR3Init();
+ }
if (RT_FAILURE(rc))
{
if (rc == VERR_ACCESS_DENIED)
@@ -790,12 +817,19 @@ int main(int argc, char **argv)
* Check if we're the specially spawned VBoxService.exe process that
* handles page fusion. This saves an extra executable.
*/
- if ( argc == 2
- && !strcmp(argv[1], "--pagefusionfork"))
+ if ( argc == 2
+ && !RTStrICmp(argv[1], "pagefusion"))
return VBoxServicePageSharingInitFork();
#endif
- char szLogFile[RTPATH_MAX + 128] = "";
+#ifdef VBOX_WITH_GUEST_CONTROL
+ /*
+ * Check if we're the specially spawned VBoxService.exe process that
+ * handles a guest control session.
+ */
+ if (fUserSession)
+ return VBoxServiceControlSessionForkInit(argc, argv);
+#endif
/*
* Parse the arguments.
@@ -845,17 +879,17 @@ int main(int argc, char **argv)
{
bool fFound = false;
- if (cch > sizeof("enable-") && !memcmp(psz, "enable-", sizeof("enable-") - 1))
+ if (cch > sizeof("enable-") && !memcmp(psz, RT_STR_TUPLE("enable-")))
for (unsigned j = 0; !fFound && j < RT_ELEMENTS(g_aServices); j++)
if ((fFound = !RTStrICmp(psz + sizeof("enable-") - 1, g_aServices[j].pDesc->pszName)))
g_aServices[j].fEnabled = true;
- if (cch > sizeof("disable-") && !memcmp(psz, "disable-", sizeof("disable-") - 1))
+ if (cch > sizeof("disable-") && !memcmp(psz, RT_STR_TUPLE("disable-")))
for (unsigned j = 0; !fFound && j < RT_ELEMENTS(g_aServices); j++)
if ((fFound = !RTStrICmp(psz + sizeof("disable-") - 1, g_aServices[j].pDesc->pszName)))
g_aServices[j].fEnabled = false;
- if (cch > sizeof("only-") && !memcmp(psz, "only-", sizeof("only-") - 1))
+ if (cch > sizeof("only-") && !memcmp(psz, RT_STR_TUPLE("only-")))
for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
{
g_aServices[j].fEnabled = !RTStrICmp(psz + sizeof("only-") - 1, g_aServices[j].pDesc->pszName);
@@ -925,7 +959,7 @@ int main(int argc, char **argv)
case 'l':
{
rc = VBoxServiceArgString(argc, argv, psz + 1, &i,
- szLogFile, sizeof(szLogFile));
+ g_szLogFile, sizeof(g_szLogFile));
if (rc)
return rc;
psz = NULL;
@@ -960,10 +994,10 @@ int main(int argc, char **argv)
if (vboxServiceCountEnabledServices() == 0)
return RTMsgErrorExit(RTEXITCODE_SYNTAX, "At least one service must be enabled\n");
- rc = VBoxServiceLogCreate(strlen(szLogFile) ? szLogFile : NULL);
+ rc = VBoxServiceLogCreate(strlen(g_szLogFile) ? g_szLogFile : NULL);
if (RT_FAILURE(rc))
return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to create release log (%s, %Rrc)",
- strlen(szLogFile) ? szLogFile : "<None>", rc);
+ strlen(g_szLogFile) ? g_szLogFile : "<None>", rc);
/* Call pre-init if we didn't do it already. */
rcExit = vboxServiceLazyPreInit();