Changeset 1853

Show
Ignore:
Timestamp:
22/09/2007 00:03:10 (16 months ago)
Author:
chris
Message:

Record the exit status of the daemon when running as a service, and
return it to Windows so that Windows doesn't tell the admin that
"the service did not report an error" when it stopped unexpectedly.

When failing to contact the SCM, report a textual error message as
well as the error code.

Make OurService?() take a const char * instead of char *, so that we can
pass it a std::string.c_str().

InstallService? creates service using "-s" option instead of "--service",
which no longer works once we use getopt() for option processing
(to follow).

Location:
box/chris/general/bin/bbackupd
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • box/chris/general/bin/bbackupd/Win32BackupService.cpp

    r1813 r1853  
    1515Win32BackupService* gpDaemonService = NULL; 
    1616extern HANDLE gStopServiceEvent; 
     17extern DWORD gServiceReturnCode; 
    1718 
    1819unsigned int WINAPI RunService(LPVOID lpParameter) 
    1920{ 
    2021        DWORD retVal = gpDaemonService->WinService((const char*) lpParameter); 
     22        gServiceReturnCode = retVal; 
    2123        SetEvent(gStopServiceEvent); 
    2224        return retVal; 
  • box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp

    r1813 r1853  
    3131SERVICE_STATUS_HANDLE gServiceStatusHandle = 0; 
    3232HANDLE gStopServiceEvent = 0; 
     33DWORD gServiceReturnCode = 0; 
    3334 
    3435#define SERVICE_NAME "boxbackup" 
     
    4445        char buf[256]; 
    4546        memset(buf, 0, sizeof(buf)); 
    46         _snprintf(buf, sizeof(buf)-1, "%s (%d)", s, err); 
     47        _snprintf(buf, sizeof(buf)-1, "%s: %s", s, 
     48                GetErrorMessage(err).c_str()); 
    4749        BOX_ERROR(buf); 
    4850        MessageBox(0, buf, "Error",  
     
    157159                gServiceStatus.dwControlsAccepted &=  
    158160                        ~(SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN); 
     161 
    159162                gServiceStatus.dwCurrentState = SERVICE_STOPPED; 
     163 
     164                if (gServiceReturnCode != 0) 
     165                { 
     166                        gServiceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; 
     167                        gServiceStatus.dwServiceSpecificExitCode = gServiceReturnCode; 
     168                } 
     169 
    160170                SetServiceStatus(gServiceStatusHandle, &gServiceStatus); 
    161171        } 
    162172} 
    163173 
    164 int OurService(char* pConfigFileName) 
    165 { 
    166         spConfigFileName = pConfigFileName; 
     174int OurService(const char* pConfigFileName) 
     175{ 
     176        spConfigFileName = strdup(pConfigFileName); 
    167177 
    168178        SERVICE_TABLE_ENTRY serviceTable[] =  
     
    176186        success = StartServiceCtrlDispatcher(serviceTable); 
    177187 
     188        free(spConfigFileName); 
     189        spConfigFileName = NULL; 
     190 
    178191        if (!success) 
    179192        { 
     
    223236 
    224237        std::string cmdWithArgs(cmd); 
    225         cmdWithArgs += " --service"; 
     238        cmdWithArgs += " -s"; 
    226239 
    227240        if (pConfigFileName != NULL) 
  • box/chris/general/bin/bbackupd/Win32ServiceFunctions.h

    r1813 r1853  
    1515int RemoveService  (void); 
    1616int InstallService (const char* pConfigFilePath); 
    17 int OurService     (char* pConfigFileName); 
     17int OurService     (const char* pConfigFileName); 
    1818 
    1919#endif