VirtualBox

Changeset 25159 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Dec 3, 2009 10:49:02 AM (15 years ago)
Author:
vboxsync
Message:

VBoxService: Various fixes and improvements for NT4 and up:

  • Shuts down correctly on NT4.
  • SCM gets notified if shutting down takes a bit longer than expected.
Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
5 edited

Legend:

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

    r23139 r25159  
    6969                                 DACL_SECURITY_INFORMATION,
    7070                                 NULL, NULL, &pOldDACL, NULL, &pSD);
    71     if (ERROR_SUCCESS != dwRes) 
     71    if (ERROR_SUCCESS != dwRes)
    7272    {
    7373        if (dwRes == ERROR_FILE_NOT_FOUND)
     
    8888    /* Create a new ACL that merges the new ACE into the existing DACL. */
    8989    dwRes = SetEntriesInAcl(1, &ea, pOldDACL, &pNewDACL);
    90     if (ERROR_SUCCESS != dwRes) 
     90    if (ERROR_SUCCESS != dwRes)
    9191    {
    9292        VBoxServiceError("AddAceToObjectsSecurityDescriptor: SetEntriesInAcl: Error %u\n", dwRes);
     
    9898                                 DACL_SECURITY_INFORMATION,
    9999                                 NULL, NULL, pNewDACL, NULL);
    100     if (ERROR_SUCCESS != dwRes) 
     100    if (ERROR_SUCCESS != dwRes)
    101101    {
    102102        VBoxServiceError("AddAceToObjectsSecurityDescriptor: SetNamedSecurityInfo: Error %u\n", dwRes);
     
    115115}
    116116
    117 BOOL VBoxServiceWinSetStatus (DWORD a_dwStatus)
     117BOOL VBoxServiceWinSetStatus (DWORD dwStatus, DWORD dwCheckPoint /*= 0 */)
    118118{
    119119    if (NULL == g_hWinServiceStatus) /* Program could be in testing mode, so no service environment available. */
    120120        return FALSE;
    121121
    122     VBoxServiceVerbose(2, "Setting service status to: %ld\n", a_dwStatus);
    123     g_rcWinService  = a_dwStatus;
     122    VBoxServiceVerbose(2, "Setting service status to: %ld\n", dwStatus);
     123    g_rcWinService  = dwStatus;
    124124
    125125    SERVICE_STATUS ss;
     
    127127    ss.dwCurrentState             = g_rcWinService;
    128128    ss.dwControlsAccepted             = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
    129     ss.dwWin32ExitCode            = NOERROR;
    130     ss.dwServiceSpecificExitCode  = NOERROR;
    131     ss.dwCheckPoint               = 0;
     129    ss.dwWin32ExitCode            = NO_ERROR;
     130    ss.dwServiceSpecificExitCode  = 0; /* Not used */
     131    ss.dwCheckPoint               = dwCheckPoint;
    132132    ss.dwWaitHint                 = 3000;
    133133
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp

    r23029 r25159  
    283283        if (g_aServices[j].fEnabled)
    284284        {
    285 
    286285            rc = g_aServices[j].pDesc->pfnInit();
    287286            if (RT_FAILURE(rc))
     
    317316        RTThreadUserWait(g_aServices[j].Thread, 60 * 1000);
    318317        if (g_aServices[j].fShutdown)
     318        {
     319            VBoxServiceError("Service '%s' failed to start!\n", g_aServices[j].pDesc->pszName);
    319320            rc = VERR_GENERAL_FAILURE;
     321        }
    320322    }
    321323    if (RT_SUCCESS(rc))
     
    329331        }
    330332    }
    331 
    332     /* Should never get here. */
    333333    return rc;
    334334}
     
    355355            if (g_aServices[j].Thread != NIL_RTTHREAD)
    356356            {
    357                 int rc = RTThreadWait(g_aServices[j].Thread, 30*1000, NULL);
     357                int rc;
     358                VBoxServiceVerbose(2, "Waiting for service '%s' to stop ...\n", g_aServices[j].pDesc->pszName);
     359                for (int i=0; i<30; i++) /* Wait 30 seconds in total */
     360                {
     361                    rc = RTThreadWait(g_aServices[j].Thread, 1000 /* Wait 1 second */, NULL);
     362                    if (RT_SUCCESS(rc))
     363                        break;
     364#ifdef RT_OS_WINDOWS
     365                    /* Notify SCM that it takes a bit longer ... */
     366                    VBoxServiceWinSetStatus(SERVICE_STOP_PENDING, i);
     367#endif
     368                }
    358369                if (RT_FAILURE(rc))
    359370                    VBoxServiceError("Service '%s' failed to stop. (%Rrc)\n", g_aServices[j].pDesc->pszName, rc);
    360371            }
     372            VBoxServiceVerbose(3, "Terminating service '%s' (%d) ...\n", g_aServices[j].pDesc->pszName, j);
    361373            g_aServices[j].pDesc->pfnTerm();
    362374        }
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceExec.cpp

    r23653 r25159  
    347347            OSVERSIONINFOEX OSInfoEx;
    348348            RT_ZERO(OSInfoEx);
    349             OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
     349            OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    350350            if (    GetVersionEx((LPOSVERSIONINFO) &OSInfoEx)
    351351                &&  OSInfoEx.dwPlatformId == VER_PLATFORM_WIN32_NT
     
    505505    g_uExecGuestPropSvcClientID = 0;
    506506
    507     RTSemEventMultiDestroy(g_hExecEvent);
    508     g_hExecEvent = NIL_RTSEMEVENTMULTI;
     507    if (g_hExecEvent != NIL_RTSEMEVENTMULTI)
     508    {
     509        RTSemEventMultiDestroy(g_hExecEvent);
     510        g_hExecEvent = NIL_RTSEMEVENTMULTI;
     511    }
    509512}
    510513
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h

    r23575 r25159  
    146146/** Uninstalls the service from the registry. */
    147147extern int VBoxServiceWinUninstall(void);
     148/** Reports our current status to the SCM. */
     149extern BOOL VBoxServiceWinSetStatus (DWORD dwStatus, DWORD dwCheckPoint = 0);
    148150#ifdef VBOX_WITH_GUEST_PROPS
    149151/** Detects wheter a user is logged on based on the enumerated processes. */
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceTimeSync.cpp

    r24540 r25159  
    271271#ifdef RT_OS_WINDOWS
    272272/** @todo r=bird: NT4 doesn't have GetSystemTimeAdjustment. */
     273    if (g_hTokenProcess == NULL) /* Is the token already closed when shutting down? */
     274        return false;
     275
    273276    DWORD dwWinTimeAdjustment, dwWinNewTimeAdjustment, dwWinTimeIncrement;
    274277    BOOL  fWinTimeAdjustmentDisabled;
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