Changeset 36328 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Mar 21, 2011 4:45:21 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 70659
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp
r36185 r36328 122 122 * @returns 1. 123 123 */ 124 static int VBoxServiceUsage(void)124 static int vboxServiceUsage(void) 125 125 { 126 126 RTPrintf("Usage:\n" … … 287 287 * @param pvUser The service index. 288 288 */ 289 static DECLCALLBACK(int) VBoxServiceThread(RTTHREAD ThreadSelf, void *pvUser)289 static DECLCALLBACK(int) vboxServiceThread(RTTHREAD ThreadSelf, void *pvUser) 290 290 { 291 291 const unsigned i = (uintptr_t)pvUser; … … 308 308 309 309 /** 310 * Check if at least one service should be started. 311 */ 312 static bool VBoxServiceCheckStartedServices(void) 313 { 314 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++) 315 if (g_aServices[j].fEnabled) 316 return true; 317 318 return false; 310 * Count the number of enabled services. 311 */ 312 static unsigned vboxServiceCountEnabledServices(void) 313 { 314 unsigned cEnabled = 0; 315 for (unsigned i = 0; i < RT_ELEMENTS(g_aServices); i++) 316 cEnabled += g_aServices[i].fEnabled; 317 return cEnabled; 319 318 } 320 319 … … 365 364 366 365 VBoxServiceVerbose(2, "Starting service '%s' ...\n", g_aServices[j].pDesc->pszName); 367 rc = RTThreadCreate(&g_aServices[j].Thread, VBoxServiceThread, (void *)(uintptr_t)j, 0,366 rc = RTThreadCreate(&g_aServices[j].Thread, vboxServiceThread, (void *)(uintptr_t)j, 0, 368 367 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, g_aServices[j].pDesc->pszName); 369 368 if (RT_FAILURE(rc)) … … 585 584 586 585 /* 587 * Parse the arguments. 586 * Parse the arguments . 587 * . 588 * Note! This code predates RTGetOpt, thus the manual parsing. 588 589 */ 589 590 bool fDaemonize = true; … … 682 683 case 'h': 683 684 case '?': 684 return VBoxServiceUsage();685 return vboxServiceUsage(); 685 686 686 687 #ifdef RT_OS_WINDOWS … … 716 717 } 717 718 719 /* Check that at least one service is enabled. */ 720 if (vboxServiceCountEnabledServices() == 0) 721 return VBoxServiceSyntax("At least one service must be enabled.\n"); 722 718 723 #ifdef RT_OS_WINDOWS 719 724 /* 720 725 * Make sure only one instance of VBoxService runs at a time. Create a 721 726 * global mutex for that. 727 * 728 * Note! The \\Global\ namespace was introduced with Win2K, thus the 729 * version check. 730 * Note! If the mutex exists CreateMutex will open it and set last error to 731 * ERROR_ALREADY_EXISTS. 722 732 */ 723 733 OSVERSIONINFOEX OSInfoEx; … … 725 735 OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 726 736 737 SetLastError(NO_ERROR); 727 738 HANDLE hMutexAppRunning; 728 if ( GetVersionEx((LPOSVERSIONINFO) 739 if ( GetVersionEx((LPOSVERSIONINFO)&OSInfoEx) 729 740 && OSInfoEx.dwPlatformId == VER_PLATFORM_WIN32_NT 730 741 && OSInfoEx.dwMajorVersion >= 5 /* NT 5.0 a.k.a W2K */) 731 {732 742 hMutexAppRunning = CreateMutex(NULL, FALSE, VBOXSERVICE_NAME_GLOBAL); 733 }734 743 else 735 {736 /* On older Windows OSes (like NT4) don't use the global namespace737 * needed for terminal servers on Win2K+. */738 744 hMutexAppRunning = CreateMutex(NULL, FALSE, VBOXSERVICE_NAME); 739 } 740 if ( hMutexAppRunning != NULL 741 && GetLastError() == ERROR_ALREADY_EXISTS) 745 if (hMutexAppRunning == NULL) 746 { 747 VBoxServiceError("CreateMutex failed with last error %u! Terminating", GetLastError()); 748 return RTEXITCODE_FAILURE; 749 } 750 if (GetLastError() == ERROR_ALREADY_EXISTS) 742 751 { 743 752 VBoxServiceError("%s is already running! Terminating.", g_pszProgName); 744 745 /* Close the mutex for this application instance. */746 753 CloseHandle(hMutexAppRunning); 747 hMutexAppRunning = NULL;748 749 754 return RTEXITCODE_FAILURE; 750 755 } 751 #else /* !RT_OS_WINDOWS */ 752 /** @todo Add PID file creation here. */ 753 #endif /* RT_OS_WINDOWS */ 754 755 /* 756 * Check that at least one service is enabled. 757 */ 758 if (!VBoxServiceCheckStartedServices()) 759 return VBoxServiceSyntax("At least one service must be enabled.\n"); 756 #else /* !RT_OS_WINDOWS */ 757 /** @todo Add PID file creation here? */ 758 #endif /* !RT_OS_WINDOWS */ 760 759 761 760 VBoxServiceVerbose(0, "%s r%s started. Verbose level = %d\n", … … 807 806 #ifdef RT_OS_WINDOWS 808 807 /* 809 * Release instance mutex if we got it. 810 */ 811 if (hMutexAppRunning != NULL) 812 { 813 ::CloseHandle(hMutexAppRunning); 814 hMutexAppRunning = NULL; 815 } 808 * Cleanup mutex. 809 */ 810 CloseHandle(hMutexAppRunning); 816 811 #endif 817 812
Note:
See TracChangeset
for help on using the changeset viewer.