VirtualBox

Ignore:
Timestamp:
Apr 22, 2010 2:48:16 PM (15 years ago)
Author:
vboxsync
Message:

VBoxService: properly shutdown the serice on normal signals; cosmetic fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp

    r27634 r28599  
    3030#endif
    3131#include <errno.h>
    32 
     32#ifndef RT_OS_WINDOWS
     33# include <signal.h>
     34#endif
     35
     36#include "product-generated.h"
    3337#include <iprt/asm.h>
    3438#include <iprt/buildconfig.h>
     
    133137        RTPrintf("    --enable-%-10s Enables the %s service. (default)\n", g_aServices[j].pDesc->pszName, g_aServices[j].pDesc->pszName);
    134138        RTPrintf("    --disable-%-9s Disables the %s service.\n", g_aServices[j].pDesc->pszName, g_aServices[j].pDesc->pszName);
    135         RTPrintf("%s", g_aServices[j].pDesc->pszOptions);
     139        if (g_aServices[j].pDesc->pszOptions)
     140            RTPrintf("%s", g_aServices[j].pDesc->pszOptions);
    136141    }
    137142    RTPrintf("\n"
    138              " Copyright (C) 2009 Sun Microsystems, Inc.\n");
     143             " Copyright (C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n");
    139144
    140145    return 1;
     
    385390    VBoxServiceVerbose(2, "Stopping services returned: rc=%Rrc\n", rc);
    386391    return rc;
     392}
     393
     394/**
     395 * Signal handler for properly shutting down the services on Posix platforms.
     396 */
     397static void VBoxServiceSignalHandler(int /* sig */)
     398{
     399    VBoxServiceVerbose(2, "VBoxServiceSignalHandler hit\n");
     400    /* Flag the main service that we want to terminate */
     401    g_fShutdown = 1;
     402    unsigned iMain = VBoxServiceGetStartedServices();
     403    /* Get the main thread out of the waiting loop */
     404    g_aServices[iMain].pDesc->pfnStop();
    387405}
    388406
     
    603621         * Start the service, enter the main threads run loop and stop them again when it returns.
    604622         */
     623#ifndef RT_OS_WINDOWS
     624        struct sigaction sa;
     625        sa.sa_handler = VBoxServiceSignalHandler;
     626        sigemptyset(&sa.sa_mask);
     627        sa.sa_flags = 0;
     628        sigaction(SIGHUP, &sa, NULL);
     629        sigaction(SIGINT, &sa, NULL);
     630        sigaction(SIGQUIT, &sa, NULL);
     631        sigaction(SIGABRT, &sa, NULL);
     632        sigaction(SIGTERM, &sa, NULL);
     633#endif
    605634        rc = VBoxServiceStartServices(iMain);
    606635        VBoxServiceStopServices();
Note: See TracChangeset for help on using the changeset viewer.

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