VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp@ 76409

Last change on this file since 76409 was 75726, checked in by vboxsync, 6 years ago

VBoxService: Added SIGCHLD to sigwait() call to make darwin (10.9.5) work. Got woken up with the first set signal in signalMask otherwise, causing the daemon to quit. (Only happens with --only-control and after blocking SIGCHLD while doing HGCM message getting from the host.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.1 KB
Line 
1/* $Id: VBoxService.cpp 75726 2018-11-25 20:12:28Z vboxsync $ */
2/** @file
3 * VBoxService - Guest Additions Service Skeleton.
4 */
5
6/*
7 * Copyright (C) 2007-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/** @page pg_vgsvc VBoxService
20 *
21 * VBoxService is a root daemon for implementing guest additions features.
22 *
23 * It is structured as one binary that contains many sub-services. The reason
24 * for this is partially historical and partially practical. The practical
25 * reason is that the VBoxService binary is typically statically linked, at
26 * least with IPRT and the guest library, so we save quite a lot of space having
27 * on single binary instead individual binaries for each sub-service and their
28 * helpers (currently up to 9 subservices and 8 helpers). The historical is
29 * simply that it started its life on OS/2 dreaming of conquring Windows next,
30 * so it kind of felt natural to have it all in one binary.
31 *
32 * Even if it's structured as a single binary, it is possible, by using command
33 * line options, to start each subservice as an individual process.
34 *
35 * Subservices:
36 * - @subpage pg_vgsvc_timesync "Time Synchronization"
37 * - @subpage pg_vgsvc_vminfo "VM Information"
38 * - @subpage pg_vgsvc_vmstats "VM Statistics"
39 * - @subpage pg_vgsvc_gstctrl "Guest Control"
40 * - @subpage pg_vgsvc_pagesharing "Page Sharing"
41 * - @subpage pg_vgsvc_memballoon "Memory Balooning"
42 * - @subpage pg_vgsvc_cpuhotplug "CPU Hot-Plugging"
43 * - @subpage pg_vgsvc_automount "Shared Folder Automounting"
44 * - @subpage pg_vgsvc_clipboard "Clipboard (OS/2 only)"
45 *
46 * Now, since the service predates a lot of stuff, including RTGetOpt, we're
47 * currently doing our own version of argument parsing here, which is kind of
48 * stupid. That will hopefully be cleaned up eventually.
49 */
50
51
52/*********************************************************************************************************************************
53* Header Files *
54*********************************************************************************************************************************/
55/** @todo LOG_GROUP*/
56#ifndef _MSC_VER
57# include <unistd.h>
58#endif
59#include <errno.h>
60#ifndef RT_OS_WINDOWS
61# include <signal.h>
62# ifdef RT_OS_OS2
63# define pthread_sigmask sigprocmask
64# endif
65#endif
66#ifdef RT_OS_FREEBSD
67# include <pthread.h>
68#endif
69
70#include <package-generated.h>
71#include "product-generated.h"
72
73#include <iprt/asm.h>
74#include <iprt/buildconfig.h>
75#include <iprt/initterm.h>
76#include <iprt/file.h>
77#ifdef DEBUG
78# include <iprt/memtracker.h>
79#endif
80#include <iprt/message.h>
81#include <iprt/path.h>
82#include <iprt/process.h>
83#include <iprt/semaphore.h>
84#include <iprt/string.h>
85#include <iprt/stream.h>
86#include <iprt/system.h>
87#include <iprt/thread.h>
88
89#include <VBox/log.h>
90
91#include "VBoxServiceInternal.h"
92#ifdef VBOX_WITH_VBOXSERVICE_CONTROL
93# include "VBoxServiceControl.h"
94#endif
95#ifdef VBOX_WITH_VBOXSERVICE_TOOLBOX
96# include "VBoxServiceToolBox.h"
97#endif
98
99
100/*********************************************************************************************************************************
101* Global Variables *
102*********************************************************************************************************************************/
103/** The program name (derived from argv[0]). */
104char *g_pszProgName = (char *)"";
105/** The current verbosity level. */
106unsigned g_cVerbosity = 0;
107char g_szLogFile[RTPATH_MAX + 128] = "";
108char g_szPidFile[RTPATH_MAX] = "";
109/** Logging parameters. */
110/** @todo Make this configurable later. */
111static PRTLOGGER g_pLoggerRelease = NULL;
112static uint32_t g_cHistory = 10; /* Enable log rotation, 10 files. */
113static uint32_t g_uHistoryFileTime = RT_SEC_1DAY; /* Max 1 day per file. */
114static uint64_t g_uHistoryFileSize = 100 * _1M; /* Max 100MB per file. */
115/** Critical section for (debug) logging. */
116#ifdef DEBUG
117 RTCRITSECT g_csLog;
118#endif
119/** The default service interval (the -i | --interval) option). */
120uint32_t g_DefaultInterval = 0;
121#ifdef RT_OS_WINDOWS
122/** Signal shutdown to the Windows service thread. */
123static bool volatile g_fWindowsServiceShutdown;
124/** Event the Windows service thread waits for shutdown. */
125static RTSEMEVENT g_hEvtWindowsService;
126#endif
127
128/**
129 * The details of the services that has been compiled in.
130 */
131static struct
132{
133 /** Pointer to the service descriptor. */
134 PCVBOXSERVICE pDesc;
135 /** The worker thread. NIL_RTTHREAD if it's the main thread. */
136 RTTHREAD Thread;
137 /** Whether Pre-init was called. */
138 bool fPreInited;
139 /** Shutdown indicator. */
140 bool volatile fShutdown;
141 /** Indicator set by the service thread exiting. */
142 bool volatile fStopped;
143 /** Whether the service was started or not. */
144 bool fStarted;
145 /** Whether the service is enabled or not. */
146 bool fEnabled;
147} g_aServices[] =
148{
149#ifdef VBOX_WITH_VBOXSERVICE_CONTROL
150 { &g_Control, NIL_RTTHREAD, false, false, false, false, true },
151#endif
152#ifdef VBOX_WITH_VBOXSERVICE_TIMESYNC
153 { &g_TimeSync, NIL_RTTHREAD, false, false, false, false, true },
154#endif
155#ifdef VBOX_WITH_VBOXSERVICE_CLIPBOARD
156 { &g_Clipboard, NIL_RTTHREAD, false, false, false, false, true },
157#endif
158#ifdef VBOX_WITH_VBOXSERVICE_VMINFO
159 { &g_VMInfo, NIL_RTTHREAD, false, false, false, false, true },
160#endif
161#ifdef VBOX_WITH_VBOXSERVICE_CPUHOTPLUG
162 { &g_CpuHotPlug, NIL_RTTHREAD, false, false, false, false, true },
163#endif
164#ifdef VBOX_WITH_VBOXSERVICE_MANAGEMENT
165# ifdef VBOX_WITH_MEMBALLOON
166 { &g_MemBalloon, NIL_RTTHREAD, false, false, false, false, true },
167# endif
168 { &g_VMStatistics, NIL_RTTHREAD, false, false, false, false, true },
169#endif
170#if defined(VBOX_WITH_VBOXSERVICE_PAGE_SHARING)
171 { &g_PageSharing, NIL_RTTHREAD, false, false, false, false, true },
172#endif
173#ifdef VBOX_WITH_SHARED_FOLDERS
174 { &g_AutoMount, NIL_RTTHREAD, false, false, false, false, true },
175#endif
176};
177
178
179/*
180 * Default call-backs for services which do not need special behaviour.
181 */
182
183/**
184 * @interface_method_impl{VBOXSERVICE,pfnPreInit, Default Implementation}
185 */
186DECLCALLBACK(int) VGSvcDefaultPreInit(void)
187{
188 return VINF_SUCCESS;
189}
190
191
192/**
193 * @interface_method_impl{VBOXSERVICE,pfnOption, Default Implementation}
194 */
195DECLCALLBACK(int) VGSvcDefaultOption(const char **ppszShort, int argc,
196 char **argv, int *pi)
197{
198 NOREF(ppszShort);
199 NOREF(argc);
200 NOREF(argv);
201 NOREF(pi);
202
203 return -1;
204}
205
206
207/**
208 * @interface_method_impl{VBOXSERVICE,pfnInit, Default Implementation}
209 */
210DECLCALLBACK(int) VGSvcDefaultInit(void)
211{
212 return VINF_SUCCESS;
213}
214
215
216/**
217 * @interface_method_impl{VBOXSERVICE,pfnTerm, Default Implementation}
218 */
219DECLCALLBACK(void) VGSvcDefaultTerm(void)
220{
221 return;
222}
223
224
225/**
226 * @callback_method_impl{FNRTLOGPHASE, Release logger callback}
227 */
228static DECLCALLBACK(void) vgsvcLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog)
229{
230 /* Some introductory information. */
231 static RTTIMESPEC s_TimeSpec;
232 char szTmp[256];
233 if (enmPhase == RTLOGPHASE_BEGIN)
234 RTTimeNow(&s_TimeSpec);
235 RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp));
236
237 switch (enmPhase)
238 {
239 case RTLOGPHASE_BEGIN:
240 {
241 pfnLog(pLoggerRelease,
242 "VBoxService %s r%s (verbosity: %u) %s (%s %s) release log\n"
243 "Log opened %s\n",
244 RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity, VBOX_BUILD_TARGET,
245 __DATE__, __TIME__, szTmp);
246
247 int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
248 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
249 pfnLog(pLoggerRelease, "OS Product: %s\n", szTmp);
250 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
251 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
252 pfnLog(pLoggerRelease, "OS Release: %s\n", szTmp);
253 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
254 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
255 pfnLog(pLoggerRelease, "OS Version: %s\n", szTmp);
256 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp));
257 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
258 pfnLog(pLoggerRelease, "OS Service Pack: %s\n", szTmp);
259
260 /* the package type is interesting for Linux distributions */
261 char szExecName[RTPATH_MAX];
262 char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
263 pfnLog(pLoggerRelease,
264 "Executable: %s\n"
265 "Process ID: %u\n"
266 "Package type: %s"
267#ifdef VBOX_OSE
268 " (OSE)"
269#endif
270 "\n",
271 pszExecName ? pszExecName : "unknown",
272 RTProcSelf(),
273 VBOX_PACKAGE_STRING);
274 break;
275 }
276
277 case RTLOGPHASE_PREROTATE:
278 pfnLog(pLoggerRelease, "Log rotated - Log started %s\n", szTmp);
279 break;
280
281 case RTLOGPHASE_POSTROTATE:
282 pfnLog(pLoggerRelease, "Log continuation - Log started %s\n", szTmp);
283 break;
284
285 case RTLOGPHASE_END:
286 pfnLog(pLoggerRelease, "End of log file - Log started %s\n", szTmp);
287 break;
288
289 default:
290 /* nothing */
291 break;
292 }
293}
294
295
296/**
297 * Creates the default release logger outputting to the specified file.
298 *
299 * Pass NULL to disabled logging.
300 *
301 * @return IPRT status code.
302 * @param pszLogFile Filename for log output. NULL disables logging
303 * (r=bird: No, it doesn't!).
304 */
305int VGSvcLogCreate(const char *pszLogFile)
306{
307 /* Create release logger (stdout + file). */
308 static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
309 RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME;
310#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
311 fFlags |= RTLOGFLAGS_USECRLF;
312#endif
313 int rc = RTLogCreateEx(&g_pLoggerRelease, fFlags, "all",
314#ifdef DEBUG
315 "VBOXSERVICE_LOG",
316#else
317 "VBOXSERVICE_RELEASE_LOG",
318#endif
319 RT_ELEMENTS(s_apszGroups), s_apszGroups,
320 RTLOGDEST_STDOUT | RTLOGDEST_USER,
321 vgsvcLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime,
322 NULL /*pErrInfo*/, "%s", pszLogFile ? pszLogFile : "");
323 if (RT_SUCCESS(rc))
324 {
325 /* register this logger as the release logger */
326 RTLogRelSetDefaultInstance(g_pLoggerRelease);
327
328 /* Explicitly flush the log in case of VBOXSERVICE_RELEASE_LOG=buffered. */
329 RTLogFlush(g_pLoggerRelease);
330 }
331
332 return rc;
333}
334
335
336/**
337 * Logs a verbose message.
338 *
339 * @param pszFormat The message text.
340 * @param va Format arguments.
341 */
342void VGSvcLogV(const char *pszFormat, va_list va)
343{
344#ifdef DEBUG
345 int rc = RTCritSectEnter(&g_csLog);
346 if (RT_SUCCESS(rc))
347 {
348#endif
349 char *psz = NULL;
350 RTStrAPrintfV(&psz, pszFormat, va);
351
352 AssertPtr(psz);
353 LogRel(("%s", psz));
354
355 RTStrFree(psz);
356#ifdef DEBUG
357 RTCritSectLeave(&g_csLog);
358 }
359#endif
360}
361
362
363/**
364 * Destroys the currently active logging instance.
365 */
366void VGSvcLogDestroy(void)
367{
368 RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
369}
370
371
372/**
373 * Displays the program usage message.
374 *
375 * @returns 1.
376 */
377static int vgsvcUsage(void)
378{
379 RTPrintf("Usage:\n"
380 " %-12s [-f|--foreground] [-v|--verbose] [-l|--logfile <file>]\n"
381 " [-p|--pidfile <file>] [-i|--interval <seconds>]\n"
382 " [--disable-<service>] [--enable-<service>]\n"
383 " [--only-<service>] [-h|-?|--help]\n", g_pszProgName);
384#ifdef RT_OS_WINDOWS
385 RTPrintf(" [-r|--register] [-u|--unregister]\n");
386#endif
387 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
388 if (g_aServices[j].pDesc->pszUsage)
389 RTPrintf("%s\n", g_aServices[j].pDesc->pszUsage);
390 RTPrintf("\n"
391 "Options:\n"
392 " -i | --interval The default interval.\n"
393 " -f | --foreground Don't daemonize the program. For debugging.\n"
394 " -l | --logfile <file> Enables logging to a file.\n"
395 " -p | --pidfile <file> Write the process ID to a file.\n"
396 " -v | --verbose Increment the verbosity level. For debugging.\n"
397 " -V | --version Show version information.\n"
398 " -h | -? | --help Show this message and exit with status 1.\n"
399 );
400#ifdef RT_OS_WINDOWS
401 RTPrintf(" -r | --register Installs the service.\n"
402 " -u | --unregister Uninstall service.\n");
403#endif
404
405 RTPrintf("\n"
406 "Service-specific options:\n");
407 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
408 {
409 RTPrintf(" --enable-%-14s Enables the %s service. (default)\n", g_aServices[j].pDesc->pszName, g_aServices[j].pDesc->pszName);
410 RTPrintf(" --disable-%-13s Disables the %s service.\n", g_aServices[j].pDesc->pszName, g_aServices[j].pDesc->pszName);
411 RTPrintf(" --only-%-16s Only enables the %s service.\n", g_aServices[j].pDesc->pszName, g_aServices[j].pDesc->pszName);
412 if (g_aServices[j].pDesc->pszOptions)
413 RTPrintf("%s", g_aServices[j].pDesc->pszOptions);
414 }
415 RTPrintf("\n"
416 " Copyright (C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n");
417
418 return 1;
419}
420
421
422/**
423 * Displays an error message.
424 *
425 * @returns RTEXITCODE_FAILURE.
426 * @param pszFormat The message text.
427 * @param ... Format arguments.
428 */
429RTEXITCODE VGSvcError(const char *pszFormat, ...)
430{
431 va_list args;
432 va_start(args, pszFormat);
433 char *psz = NULL;
434 RTStrAPrintfV(&psz, pszFormat, args);
435 va_end(args);
436
437 AssertPtr(psz);
438 LogRel(("Error: %s", psz));
439
440 RTStrFree(psz);
441
442 return RTEXITCODE_FAILURE;
443}
444
445
446/**
447 * Displays a verbose message based on the currently
448 * set global verbosity level.
449 *
450 * @param iLevel Minimum log level required to display this message.
451 * @param pszFormat The message text.
452 * @param ... Format arguments.
453 */
454void VGSvcVerbose(unsigned iLevel, const char *pszFormat, ...)
455{
456 if (iLevel <= g_cVerbosity)
457 {
458 va_list va;
459 va_start(va, pszFormat);
460 VGSvcLogV(pszFormat, va);
461 va_end(va);
462 }
463}
464
465
466/**
467 * Reports the current VBoxService status to the host.
468 *
469 * This makes sure that the Failed state is sticky.
470 *
471 * @return IPRT status code.
472 * @param enmStatus Status to report to the host.
473 */
474int VGSvcReportStatus(VBoxGuestFacilityStatus enmStatus)
475{
476 /*
477 * VBoxGuestFacilityStatus_Failed is sticky.
478 */
479 static VBoxGuestFacilityStatus s_enmLastStatus = VBoxGuestFacilityStatus_Inactive;
480 VGSvcVerbose(4, "Setting VBoxService status to %u\n", enmStatus);
481 if (s_enmLastStatus != VBoxGuestFacilityStatus_Failed)
482 {
483 int rc = VbglR3ReportAdditionsStatus(VBoxGuestFacilityType_VBoxService, enmStatus, 0 /* Flags */);
484 if (RT_FAILURE(rc))
485 {
486 VGSvcError("Could not report VBoxService status (%u), rc=%Rrc\n", enmStatus, rc);
487 return rc;
488 }
489 s_enmLastStatus = enmStatus;
490 }
491 return VINF_SUCCESS;
492}
493
494
495/**
496 * Gets a 32-bit value argument.
497 * @todo Get rid of this and VGSvcArgString() as soon as we have RTOpt handling.
498 *
499 * @returns 0 on success, non-zero exit code on error.
500 * @param argc The argument count.
501 * @param argv The argument vector
502 * @param psz Where in *pi to start looking for the value argument.
503 * @param pi Where to find and perhaps update the argument index.
504 * @param pu32 Where to store the 32-bit value.
505 * @param u32Min The minimum value.
506 * @param u32Max The maximum value.
507 */
508int VGSvcArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max)
509{
510 if (*psz == ':' || *psz == '=')
511 psz++;
512 if (!*psz)
513 {
514 if (*pi + 1 >= argc)
515 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Missing value for the '%s' argument\n", argv[*pi]);
516 psz = argv[++*pi];
517 }
518
519 char *pszNext;
520 int rc = RTStrToUInt32Ex(psz, &pszNext, 0, pu32);
521 if (RT_FAILURE(rc) || *pszNext)
522 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Failed to convert interval '%s' to a number\n", psz);
523 if (*pu32 < u32Min || *pu32 > u32Max)
524 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "The timesync interval of %RU32 seconds is out of range [%RU32..%RU32]\n",
525 *pu32, u32Min, u32Max);
526 return 0;
527}
528
529
530/** @todo Get rid of this and VGSvcArgUInt32() as soon as we have RTOpt handling. */
531static int vgsvcArgString(int argc, char **argv, const char *psz, int *pi, char *pszBuf, size_t cbBuf)
532{
533 AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
534 AssertReturn(cbBuf, VERR_INVALID_PARAMETER);
535
536 if (*psz == ':' || *psz == '=')
537 psz++;
538 if (!*psz)
539 {
540 if (*pi + 1 >= argc)
541 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Missing string for the '%s' argument\n", argv[*pi]);
542 psz = argv[++*pi];
543 }
544
545 if (!RTStrPrintf(pszBuf, cbBuf, "%s", psz))
546 return RTMsgErrorExit(RTEXITCODE_FAILURE, "String for '%s' argument too big\n", argv[*pi]);
547 return 0;
548}
549
550
551/**
552 * The service thread.
553 *
554 * @returns Whatever the worker function returns.
555 * @param ThreadSelf My thread handle.
556 * @param pvUser The service index.
557 */
558static DECLCALLBACK(int) vgsvcThread(RTTHREAD ThreadSelf, void *pvUser)
559{
560 const unsigned i = (uintptr_t)pvUser;
561
562#ifndef RT_OS_WINDOWS
563 /*
564 * Block all signals for this thread. Only the main thread will handle signals.
565 */
566 sigset_t signalMask;
567 sigfillset(&signalMask);
568 pthread_sigmask(SIG_BLOCK, &signalMask, NULL);
569#endif
570
571 int rc = g_aServices[i].pDesc->pfnWorker(&g_aServices[i].fShutdown);
572 ASMAtomicXchgBool(&g_aServices[i].fShutdown, true);
573 RTThreadUserSignal(ThreadSelf);
574 return rc;
575}
576
577
578/**
579 * Lazily calls the pfnPreInit method on each service.
580 *
581 * @returns VBox status code, error message displayed.
582 */
583static RTEXITCODE vgsvcLazyPreInit(void)
584{
585 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
586 if (!g_aServices[j].fPreInited)
587 {
588 int rc = g_aServices[j].pDesc->pfnPreInit();
589 if (RT_FAILURE(rc))
590 return VGSvcError("Service '%s' failed pre-init: %Rrc\n", g_aServices[j].pDesc->pszName, rc);
591 g_aServices[j].fPreInited = true;
592 }
593 return RTEXITCODE_SUCCESS;
594}
595
596
597/**
598 * Count the number of enabled services.
599 */
600static unsigned vgsvcCountEnabledServices(void)
601{
602 unsigned cEnabled = 0;
603 for (unsigned i = 0; i < RT_ELEMENTS(g_aServices); i++)
604 cEnabled += g_aServices[i].fEnabled;
605 return cEnabled;
606}
607
608
609#ifdef RT_OS_WINDOWS
610/**
611 * Console control event callback.
612 *
613 * @returns TRUE if handled, FALSE if not.
614 * @param dwCtrlType The control event type.
615 *
616 * @remarks This is generally called on a new thread, so we're racing every
617 * other thread in the process.
618 */
619static BOOL WINAPI vgsvcWinConsoleControlHandler(DWORD dwCtrlType)
620{
621 int rc = VINF_SUCCESS;
622 bool fEventHandled = FALSE;
623 switch (dwCtrlType)
624 {
625 /* User pressed CTRL+C or CTRL+BREAK or an external event was sent
626 * via GenerateConsoleCtrlEvent(). */
627 case CTRL_BREAK_EVENT:
628 case CTRL_CLOSE_EVENT:
629 case CTRL_C_EVENT:
630 VGSvcVerbose(2, "ControlHandler: Received break/close event\n");
631 rc = VGSvcStopServices();
632 fEventHandled = TRUE;
633 break;
634 default:
635 break;
636 /** @todo Add other events here. */
637 }
638
639 if (RT_FAILURE(rc))
640 VGSvcError("ControlHandler: Event %ld handled with error rc=%Rrc\n",
641 dwCtrlType, rc);
642 return fEventHandled;
643}
644#endif /* RT_OS_WINDOWS */
645
646
647/**
648 * Starts the service.
649 *
650 * @returns VBox status code, errors are fully bitched.
651 *
652 * @remarks Also called from VBoxService-win.cpp, thus not static.
653 */
654int VGSvcStartServices(void)
655{
656 int rc;
657
658 VGSvcReportStatus(VBoxGuestFacilityStatus_Init);
659
660 /*
661 * Initialize the services.
662 */
663 VGSvcVerbose(2, "Initializing services ...\n");
664 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
665 if (g_aServices[j].fEnabled)
666 {
667 rc = g_aServices[j].pDesc->pfnInit();
668 if (RT_FAILURE(rc))
669 {
670 if (rc != VERR_SERVICE_DISABLED)
671 {
672 VGSvcError("Service '%s' failed to initialize: %Rrc\n", g_aServices[j].pDesc->pszName, rc);
673 VGSvcReportStatus(VBoxGuestFacilityStatus_Failed);
674 return rc;
675 }
676
677 g_aServices[j].fEnabled = false;
678 VGSvcVerbose(0, "Service '%s' was disabled because of missing functionality\n", g_aServices[j].pDesc->pszName);
679 }
680 }
681
682 /*
683 * Start the service(s).
684 */
685 VGSvcVerbose(2, "Starting services ...\n");
686 rc = VINF_SUCCESS;
687 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
688 {
689 if (!g_aServices[j].fEnabled)
690 continue;
691
692 VGSvcVerbose(2, "Starting service '%s' ...\n", g_aServices[j].pDesc->pszName);
693 rc = RTThreadCreate(&g_aServices[j].Thread, vgsvcThread, (void *)(uintptr_t)j, 0,
694 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, g_aServices[j].pDesc->pszName);
695 if (RT_FAILURE(rc))
696 {
697 VGSvcError("RTThreadCreate failed, rc=%Rrc\n", rc);
698 break;
699 }
700 g_aServices[j].fStarted = true;
701
702 /* Wait for the thread to initialize. */
703 /** @todo There is a race between waiting and checking
704 * the fShutdown flag of a thread here and processing
705 * the thread's actual worker loop. If the thread decides
706 * to exit the loop before we skipped the fShutdown check
707 * below the service will fail to start! */
708 /** @todo This presumably means either a one-shot service or that
709 * something has gone wrong. In the second case treating it as failure
710 * to start is probably right, so we need a way to signal the first
711 * rather than leaving the idle thread hanging around. A flag in the
712 * service description? */
713 RTThreadUserWait(g_aServices[j].Thread, 60 * 1000);
714 if (g_aServices[j].fShutdown)
715 {
716 VGSvcError("Service '%s' failed to start!\n", g_aServices[j].pDesc->pszName);
717 rc = VERR_GENERAL_FAILURE;
718 }
719 }
720
721 if (RT_SUCCESS(rc))
722 VGSvcVerbose(1, "All services started.\n");
723 else
724 {
725 VGSvcError("An error occcurred while the services!\n");
726 VGSvcReportStatus(VBoxGuestFacilityStatus_Failed);
727 }
728 return rc;
729}
730
731
732/**
733 * Stops and terminates the services.
734 *
735 * This should be called even when VBoxServiceStartServices fails so it can
736 * clean up anything that we succeeded in starting.
737 *
738 * @remarks Also called from VBoxService-win.cpp, thus not static.
739 */
740int VGSvcStopServices(void)
741{
742 VGSvcReportStatus(VBoxGuestFacilityStatus_Terminating);
743
744 /*
745 * Signal all the services.
746 */
747 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
748 ASMAtomicWriteBool(&g_aServices[j].fShutdown, true);
749
750 /*
751 * Do the pfnStop callback on all running services.
752 */
753 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
754 if (g_aServices[j].fStarted)
755 {
756 VGSvcVerbose(3, "Calling stop function for service '%s' ...\n", g_aServices[j].pDesc->pszName);
757 g_aServices[j].pDesc->pfnStop();
758 }
759
760 VGSvcVerbose(3, "All stop functions for services called\n");
761
762 /*
763 * Wait for all the service threads to complete.
764 */
765 int rc = VINF_SUCCESS;
766 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
767 {
768 if (!g_aServices[j].fEnabled) /* Only stop services which were started before. */
769 continue;
770 if (g_aServices[j].Thread != NIL_RTTHREAD)
771 {
772 VGSvcVerbose(2, "Waiting for service '%s' to stop ...\n", g_aServices[j].pDesc->pszName);
773 int rc2 = VINF_SUCCESS;
774 for (int i = 0; i < 30; i++) /* Wait 30 seconds in total */
775 {
776 rc2 = RTThreadWait(g_aServices[j].Thread, 1000 /* Wait 1 second */, NULL);
777 if (RT_SUCCESS(rc2))
778 break;
779#ifdef RT_OS_WINDOWS
780 /* Notify SCM that it takes a bit longer ... */
781 VGSvcWinSetStopPendingStatus(i + j*32);
782#endif
783 }
784 if (RT_FAILURE(rc2))
785 {
786 VGSvcError("Service '%s' failed to stop. (%Rrc)\n", g_aServices[j].pDesc->pszName, rc2);
787 rc = rc2;
788 }
789 }
790 VGSvcVerbose(3, "Terminating service '%s' (%d) ...\n", g_aServices[j].pDesc->pszName, j);
791 g_aServices[j].pDesc->pfnTerm();
792 }
793
794#ifdef RT_OS_WINDOWS
795 /*
796 * Wake up and tell the main() thread that we're shutting down (it's
797 * sleeping in VBoxServiceMainWait).
798 */
799 ASMAtomicWriteBool(&g_fWindowsServiceShutdown, true);
800 if (g_hEvtWindowsService != NIL_RTSEMEVENT)
801 {
802 VGSvcVerbose(3, "Stopping the main thread...\n");
803 int rc2 = RTSemEventSignal(g_hEvtWindowsService);
804 AssertRC(rc2);
805 }
806#endif
807
808 VGSvcVerbose(2, "Stopping services returning: %Rrc\n", rc);
809 VGSvcReportStatus(RT_SUCCESS(rc) ? VBoxGuestFacilityStatus_Paused : VBoxGuestFacilityStatus_Failed);
810 return rc;
811}
812
813
814/**
815 * Block the main thread until the service shuts down.
816 *
817 * @remarks Also called from VBoxService-win.cpp, thus not static.
818 */
819void VGSvcMainWait(void)
820{
821 int rc;
822
823 VGSvcReportStatus(VBoxGuestFacilityStatus_Active);
824
825#ifdef RT_OS_WINDOWS
826 /*
827 * Wait for the semaphore to be signalled.
828 */
829 VGSvcVerbose(1, "Waiting in main thread\n");
830 rc = RTSemEventCreate(&g_hEvtWindowsService);
831 AssertRC(rc);
832 while (!ASMAtomicReadBool(&g_fWindowsServiceShutdown))
833 {
834 rc = RTSemEventWait(g_hEvtWindowsService, RT_INDEFINITE_WAIT);
835 AssertRC(rc);
836 }
837 RTSemEventDestroy(g_hEvtWindowsService);
838 g_hEvtWindowsService = NIL_RTSEMEVENT;
839#else
840 /*
841 * Wait explicitly for a HUP, INT, QUIT, ABRT or TERM signal, blocking
842 * all important signals.
843 *
844 * The annoying EINTR/ERESTART loop is for the benefit of Solaris where
845 * sigwait returns when we receive a SIGCHLD. Kind of makes sense since
846 * the signal has to be delivered... Anyway, darwin (10.9.5) has a much
847 * worse way of dealing with SIGCHLD, apparently it'll just return any
848 * of the signals we're waiting on when SIGCHLD becomes pending on this
849 * thread. So, we wait for SIGCHLD here and ignores it.
850 */
851 sigset_t signalMask;
852 sigemptyset(&signalMask);
853 sigaddset(&signalMask, SIGHUP);
854 sigaddset(&signalMask, SIGINT);
855 sigaddset(&signalMask, SIGQUIT);
856 sigaddset(&signalMask, SIGABRT);
857 sigaddset(&signalMask, SIGTERM);
858 sigaddset(&signalMask, SIGCHLD);
859 pthread_sigmask(SIG_BLOCK, &signalMask, NULL);
860
861 int iSignal;
862 do
863 {
864 iSignal = -1;
865 rc = sigwait(&signalMask, &iSignal);
866 }
867 while ( rc == EINTR
868# ifdef ERESTART
869 || rc == ERESTART
870# endif
871 || iSignal == SIGCHLD
872 );
873
874 VGSvcVerbose(3, "VGSvcMainWait: Received signal %d (rc=%d)\n", iSignal, rc);
875#endif /* !RT_OS_WINDOWS */
876}
877
878
879int main(int argc, char **argv)
880{
881 RTEXITCODE rcExit;
882
883 /*
884 * Init globals and such.
885 */
886 int rc = RTR3InitExe(argc, &argv, 0);
887 if (RT_FAILURE(rc))
888 return RTMsgInitFailure(rc);
889 g_pszProgName = RTPathFilename(argv[0]);
890#ifdef RT_OS_WINDOWS
891 VGSvcWinResolveApis();
892#endif
893#ifdef DEBUG
894 rc = RTCritSectInit(&g_csLog);
895 AssertRC(rc);
896#endif
897
898#ifdef VBOX_WITH_VBOXSERVICE_TOOLBOX
899 /*
900 * Run toolbox code before all other stuff since these things are simpler
901 * shell/file/text utility like programs that just happens to be inside
902 * VBoxService and shouldn't be subject to /dev/vboxguest, pid-files and
903 * global mutex restrictions.
904 */
905 if (VGSvcToolboxMain(argc, argv, &rcExit))
906 return rcExit;
907#endif
908
909 bool fUserSession = false;
910#ifdef VBOX_WITH_VBOXSERVICE_CONTROL
911 /*
912 * Check if we're the specially spawned VBoxService.exe process that
913 * handles a guest control session.
914 */
915 if ( argc >= 2
916 && !RTStrICmp(argv[1], "guestsession"))
917 fUserSession = true;
918#endif
919
920 /*
921 * Connect to the kernel part before daemonizing so we can fail and
922 * complain if there is some kind of problem. We need to initialize the
923 * guest lib *before* we do the pre-init just in case one of services needs
924 * do to some initial stuff with it.
925 */
926 if (fUserSession)
927 rc = VbglR3InitUser();
928 else
929 rc = VbglR3Init();
930 if (RT_FAILURE(rc))
931 {
932 if (rc == VERR_ACCESS_DENIED)
933 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Insufficient privileges to start %s! Please start with Administrator/root privileges!\n",
934 g_pszProgName);
935 return RTMsgErrorExit(RTEXITCODE_FAILURE, "VbglR3Init failed with rc=%Rrc\n", rc);
936 }
937
938#ifdef RT_OS_WINDOWS
939 /*
940 * Check if we're the specially spawned VBoxService.exe process that
941 * handles page fusion. This saves an extra statically linked executable.
942 */
943 if ( argc == 2
944 && !RTStrICmp(argv[1], "pagefusion"))
945 return VGSvcPageSharingWorkerChild();
946#endif
947
948#ifdef VBOX_WITH_VBOXSERVICE_CONTROL
949 /*
950 * Check if we're the specially spawned VBoxService.exe process that
951 * handles a guest control session.
952 */
953 if (fUserSession)
954 return VGSvcGstCtrlSessionSpawnInit(argc, argv);
955#endif
956
957 /*
958 * Parse the arguments.
959 *
960 * Note! This code predates RTGetOpt, thus the manual parsing.
961 */
962 bool fDaemonize = true;
963 bool fDaemonized = false;
964 for (int i = 1; i < argc; i++)
965 {
966 const char *psz = argv[i];
967 if (*psz != '-')
968 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Unknown argument '%s'\n", psz);
969 psz++;
970
971 /* translate long argument to short */
972 if (*psz == '-')
973 {
974 psz++;
975 size_t cch = strlen(psz);
976#define MATCHES(strconst) ( cch == sizeof(strconst) - 1 \
977 && !memcmp(psz, strconst, sizeof(strconst) - 1) )
978 if (MATCHES("foreground"))
979 psz = "f";
980 else if (MATCHES("verbose"))
981 psz = "v";
982 else if (MATCHES("version"))
983 psz = "V";
984 else if (MATCHES("help"))
985 psz = "h";
986 else if (MATCHES("interval"))
987 psz = "i";
988#ifdef RT_OS_WINDOWS
989 else if (MATCHES("register"))
990 psz = "r";
991 else if (MATCHES("unregister"))
992 psz = "u";
993#endif
994 else if (MATCHES("logfile"))
995 psz = "l";
996 else if (MATCHES("pidfile"))
997 psz = "p";
998 else if (MATCHES("daemonized"))
999 {
1000 fDaemonized = true;
1001 continue;
1002 }
1003 else
1004 {
1005 bool fFound = false;
1006
1007 if (cch > sizeof("enable-") && !memcmp(psz, RT_STR_TUPLE("enable-")))
1008 for (unsigned j = 0; !fFound && j < RT_ELEMENTS(g_aServices); j++)
1009 if ((fFound = !RTStrICmp(psz + sizeof("enable-") - 1, g_aServices[j].pDesc->pszName)))
1010 g_aServices[j].fEnabled = true;
1011
1012 if (cch > sizeof("disable-") && !memcmp(psz, RT_STR_TUPLE("disable-")))
1013 for (unsigned j = 0; !fFound && j < RT_ELEMENTS(g_aServices); j++)
1014 if ((fFound = !RTStrICmp(psz + sizeof("disable-") - 1, g_aServices[j].pDesc->pszName)))
1015 g_aServices[j].fEnabled = false;
1016
1017 if (cch > sizeof("only-") && !memcmp(psz, RT_STR_TUPLE("only-")))
1018 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
1019 {
1020 g_aServices[j].fEnabled = !RTStrICmp(psz + sizeof("only-") - 1, g_aServices[j].pDesc->pszName);
1021 if (g_aServices[j].fEnabled)
1022 fFound = true;
1023 }
1024
1025 if (!fFound)
1026 {
1027 rcExit = vgsvcLazyPreInit();
1028 if (rcExit != RTEXITCODE_SUCCESS)
1029 return rcExit;
1030 for (unsigned j = 0; !fFound && j < RT_ELEMENTS(g_aServices); j++)
1031 {
1032 rc = g_aServices[j].pDesc->pfnOption(NULL, argc, argv, &i);
1033 fFound = rc == VINF_SUCCESS;
1034 if (fFound)
1035 break;
1036 if (rc != -1)
1037 return rc;
1038 }
1039 }
1040 if (!fFound)
1041 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Unknown option '%s'\n", argv[i]);
1042 continue;
1043 }
1044#undef MATCHES
1045 }
1046
1047 /* handle the string of short options. */
1048 do
1049 {
1050 switch (*psz)
1051 {
1052 case 'i':
1053 rc = VGSvcArgUInt32(argc, argv, psz + 1, &i,
1054 &g_DefaultInterval, 1, (UINT32_MAX / 1000) - 1);
1055 if (rc)
1056 return rc;
1057 psz = NULL;
1058 break;
1059
1060 case 'f':
1061 fDaemonize = false;
1062 break;
1063
1064 case 'v':
1065 g_cVerbosity++;
1066 break;
1067
1068 case 'V':
1069 RTPrintf("%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
1070 return RTEXITCODE_SUCCESS;
1071
1072 case 'h':
1073 case '?':
1074 return vgsvcUsage();
1075
1076#ifdef RT_OS_WINDOWS
1077 case 'r':
1078 return VGSvcWinInstall();
1079
1080 case 'u':
1081 return VGSvcWinUninstall();
1082#endif
1083
1084 case 'l':
1085 {
1086 rc = vgsvcArgString(argc, argv, psz + 1, &i,
1087 g_szLogFile, sizeof(g_szLogFile));
1088 if (rc)
1089 return rc;
1090 psz = NULL;
1091 break;
1092 }
1093
1094 case 'p':
1095 {
1096 rc = vgsvcArgString(argc, argv, psz + 1, &i,
1097 g_szPidFile, sizeof(g_szPidFile));
1098 if (rc)
1099 return rc;
1100 psz = NULL;
1101 break;
1102 }
1103
1104 default:
1105 {
1106 rcExit = vgsvcLazyPreInit();
1107 if (rcExit != RTEXITCODE_SUCCESS)
1108 return rcExit;
1109
1110 bool fFound = false;
1111 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
1112 {
1113 rc = g_aServices[j].pDesc->pfnOption(&psz, argc, argv, &i);
1114 fFound = rc == VINF_SUCCESS;
1115 if (fFound)
1116 break;
1117 if (rc != -1)
1118 return rc;
1119 }
1120 if (!fFound)
1121 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Unknown option '%c' (%s)\n", *psz, argv[i]);
1122 break;
1123 }
1124 }
1125 } while (psz && *++psz);
1126 }
1127
1128 /* Check that at least one service is enabled. */
1129 if (vgsvcCountEnabledServices() == 0)
1130 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "At least one service must be enabled\n");
1131
1132 rc = VGSvcLogCreate(g_szLogFile[0] ? g_szLogFile : NULL);
1133 if (RT_FAILURE(rc))
1134 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to create release log '%s', rc=%Rrc\n",
1135 g_szLogFile[0] ? g_szLogFile : "<None>", rc);
1136
1137 /* Call pre-init if we didn't do it already. */
1138 rcExit = vgsvcLazyPreInit();
1139 if (rcExit != RTEXITCODE_SUCCESS)
1140 return rcExit;
1141
1142#ifdef RT_OS_WINDOWS
1143 /*
1144 * Make sure only one instance of VBoxService runs at a time. Create a
1145 * global mutex for that.
1146 *
1147 * Note! The \\Global\ namespace was introduced with Win2K, thus the
1148 * version check.
1149 * Note! If the mutex exists CreateMutex will open it and set last error to
1150 * ERROR_ALREADY_EXISTS.
1151 */
1152 OSVERSIONINFOEX OSInfoEx;
1153 RT_ZERO(OSInfoEx);
1154 OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
1155
1156 SetLastError(NO_ERROR);
1157 HANDLE hMutexAppRunning;
1158 if ( GetVersionEx((LPOSVERSIONINFO)&OSInfoEx)
1159 && OSInfoEx.dwPlatformId == VER_PLATFORM_WIN32_NT
1160 && OSInfoEx.dwMajorVersion >= 5 /* NT 5.0 a.k.a W2K */)
1161 hMutexAppRunning = CreateMutex(NULL, FALSE, "Global\\" VBOXSERVICE_NAME);
1162 else
1163 hMutexAppRunning = CreateMutex(NULL, FALSE, VBOXSERVICE_NAME);
1164 if (hMutexAppRunning == NULL)
1165 {
1166 DWORD dwErr = GetLastError();
1167 if ( dwErr == ERROR_ALREADY_EXISTS
1168 || dwErr == ERROR_ACCESS_DENIED)
1169 {
1170 VGSvcError("%s is already running! Terminating.\n", g_pszProgName);
1171 return RTEXITCODE_FAILURE;
1172 }
1173
1174 VGSvcError("CreateMutex failed with last error %u! Terminating.\n", GetLastError());
1175 return RTEXITCODE_FAILURE;
1176 }
1177
1178#else /* !RT_OS_WINDOWS */
1179 /** @todo Add PID file creation here? */
1180#endif /* !RT_OS_WINDOWS */
1181
1182 VGSvcVerbose(0, "%s r%s started. Verbose level = %d\n", RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity);
1183
1184 /*
1185 * Daemonize if requested.
1186 */
1187 if (fDaemonize && !fDaemonized)
1188 {
1189#ifdef RT_OS_WINDOWS
1190 VGSvcVerbose(2, "Starting service dispatcher ...\n");
1191 rcExit = VGSvcWinEnterCtrlDispatcher();
1192#else
1193 VGSvcVerbose(1, "Daemonizing...\n");
1194 rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */,
1195 false /* fRespawn */, NULL /* pcRespawn */);
1196 if (RT_FAILURE(rc))
1197 return VGSvcError("Daemon failed: %Rrc\n", rc);
1198 /* in-child */
1199#endif
1200 }
1201#ifdef RT_OS_WINDOWS
1202 else
1203#endif
1204 {
1205 /*
1206 * Windows: We're running the service as a console application now. Start the
1207 * services, enter the main thread's run loop and stop them again
1208 * when it returns.
1209 *
1210 * POSIX: This is used for both daemons and console runs. Start all services
1211 * and return immediately.
1212 */
1213#ifdef RT_OS_WINDOWS
1214# ifndef RT_OS_NT4 /** @todo r=bird: What's RT_OS_NT4??? */
1215 /* Install console control handler. */
1216 if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)vgsvcWinConsoleControlHandler, TRUE /* Add handler */))
1217 {
1218 VGSvcError("Unable to add console control handler, error=%ld\n", GetLastError());
1219 /* Just skip this error, not critical. */
1220 }
1221# endif /* !RT_OS_NT4 */
1222#endif /* RT_OS_WINDOWS */
1223 rc = VGSvcStartServices();
1224 RTFILE hPidFile = NIL_RTFILE;
1225 if (RT_SUCCESS(rc))
1226 if (g_szPidFile[0])
1227 rc = VbglR3PidFile(g_szPidFile, &hPidFile);
1228 rcExit = RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
1229 if (RT_SUCCESS(rc))
1230 VGSvcMainWait();
1231 if (g_szPidFile[0] && hPidFile != NIL_RTFILE)
1232 VbglR3ClosePidFile(g_szPidFile, hPidFile);
1233#ifdef RT_OS_WINDOWS
1234# ifndef RT_OS_NT4
1235 /* Uninstall console control handler. */
1236 if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)NULL, FALSE /* Remove handler */))
1237 {
1238 VGSvcError("Unable to remove console control handler, error=%ld\n", GetLastError());
1239 /* Just skip this error, not critical. */
1240 }
1241# endif /* !RT_OS_NT4 */
1242#else /* !RT_OS_WINDOWS */
1243 /* On Windows - since we're running as a console application - we already stopped all services
1244 * through the console control handler. So only do the stopping of services here on other platforms
1245 * where the break/shutdown/whatever signal was just received. */
1246 VGSvcStopServices();
1247#endif /* RT_OS_WINDOWS */
1248 }
1249 VGSvcReportStatus(VBoxGuestFacilityStatus_Terminated);
1250
1251#ifdef RT_OS_WINDOWS
1252 /*
1253 * Cleanup mutex.
1254 */
1255 CloseHandle(hMutexAppRunning);
1256#endif
1257
1258 VGSvcVerbose(0, "Ended.\n");
1259
1260#ifdef DEBUG
1261 RTCritSectDelete(&g_csLog);
1262 //RTMemTrackerDumpAllToStdOut();
1263#endif
1264
1265 VGSvcLogDestroy();
1266
1267 return rcExit;
1268}
1269
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette