Changeset 28603 in vbox
- Timestamp:
- Apr 22, 2010 3:48:25 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 60450
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp
r28600 r28603 259 259 { 260 260 const unsigned i = (uintptr_t)pvUser; 261 262 #ifndef RT_OS_WINDOWS 263 /* 264 * Block all signals for this thread. Only the main thread will handle signals. 265 */ 266 sigset_t signalMask; 267 sigfillset(&signalMask); 268 pthread_sigmask(SIG_BLOCK, &signalMask, NULL); 269 #endif 270 261 271 int rc = g_aServices[i].pDesc->pfnWorker(&g_aServices[i].fShutdown); 262 272 ASMAtomicXchgBool(&g_aServices[i].fShutdown, true); … … 336 346 } 337 347 } 338 if (RT_SUCCESS(rc)) 348 if ( RT_SUCCESS(rc) 349 && iMain != ~0U) 339 350 { 340 351 /* The final service runs in the main thread. */ … … 393 404 394 405 #ifndef RT_OS_WINDOWS 395 /** 396 * Signal handler for properly shutting down the services on Posix platforms. 397 */ 398 static void VBoxServiceSignalHandler(int /* sig */) 399 { 400 VBoxServiceVerbose(2, "VBoxServiceSignalHandler hit\n"); 401 /* Flag the main service that we want to terminate */ 402 g_fShutdown = 1; 403 unsigned iMain = VBoxServiceGetStartedServices(); 404 /* Get the main thread out of the waiting loop */ 405 g_aServices[iMain].pDesc->pfnStop(); 406 /* 407 * Block all important signals, then explicitly wait until one of these signal arrives. 408 */ 409 static void VBoxServiceWaitSignal(void) 410 { 411 sigset_t signalMask; 412 int iSignal; 413 sigemptyset(&signalMask); 414 sigaddset(&signalMask, SIGHUP); 415 sigaddset(&signalMask, SIGINT); 416 sigaddset(&signalMask, SIGQUIT); 417 sigaddset(&signalMask, SIGABRT); 418 sigaddset(&signalMask, SIGTERM); 419 pthread_sigmask(SIG_BLOCK, &signalMask, NULL); 420 sigwait(&signalMask, &iSignal); 421 VBoxServiceVerbose(3, "VBoxServiceWaitSignal: Received signal %d\n", iSignal); 406 422 } 407 423 #endif … … 578 594 if (iMain == ~0U) 579 595 return VBoxServiceSyntax("At least one service must be enabled.\n"); 596 597 #ifndef RT_OS_WINDOWS 598 /* 599 * POSIX: No main service thread. 600 */ 601 iMain = ~0U; 602 #endif 580 603 581 604 VBoxServiceVerbose(0, "%s r%s started. Verbose level = %d\n", … … 618 641 /* Run the app just like a console one if not daemonized. */ 619 642 #endif 620 /** @todo Make the main thread responsive to signal so it can shutdown/restart the threads on non-SIGKILL signals. */621 622 643 /* 623 * Start the service, enter the main threads run loop and stop them again when it returns. 644 * Windows: Start the services, enter the main threads' run loop and stop them 645 * again when it returns. 646 * 647 * POSIX: Start all services and return immediately. 624 648 */ 649 rc = VBoxServiceStartServices(iMain); 625 650 #ifndef RT_OS_WINDOWS 626 struct sigaction sa; 627 sa.sa_handler = VBoxServiceSignalHandler; 628 sigemptyset(&sa.sa_mask); 629 sa.sa_flags = 0; 630 sigaction(SIGHUP, &sa, NULL); 631 sigaction(SIGINT, &sa, NULL); 632 sigaction(SIGQUIT, &sa, NULL); 633 sigaction(SIGABRT, &sa, NULL); 634 sigaction(SIGTERM, &sa, NULL); 635 #endif 636 rc = VBoxServiceStartServices(iMain); 651 VBoxServiceWaitSignal(); 652 #endif 637 653 VBoxServiceStopServices(); 638 654 #ifdef RT_OS_WINDOWS
Note:
See TracChangeset
for help on using the changeset viewer.