[Box Backup-commit] COMMIT r1853 - box/chris/general/bin/bbackupd
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Sat Sep 22 00:03:10 BST 2007
Author: chris
Date: 2007-09-22 00:03:10 +0100 (Sat, 22 Sep 2007)
New Revision: 1853
Modified:
box/chris/general/bin/bbackupd/Win32BackupService.cpp
box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp
box/chris/general/bin/bbackupd/Win32ServiceFunctions.h
Log:
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).
Modified: box/chris/general/bin/bbackupd/Win32BackupService.cpp
===================================================================
--- box/chris/general/bin/bbackupd/Win32BackupService.cpp 2007-09-21 22:59:16 UTC (rev 1852)
+++ box/chris/general/bin/bbackupd/Win32BackupService.cpp 2007-09-21 23:03:10 UTC (rev 1853)
@@ -14,10 +14,12 @@
Win32BackupService* gpDaemonService = NULL;
extern HANDLE gStopServiceEvent;
+extern DWORD gServiceReturnCode;
unsigned int WINAPI RunService(LPVOID lpParameter)
{
DWORD retVal = gpDaemonService->WinService((const char*) lpParameter);
+ gServiceReturnCode = retVal;
SetEvent(gStopServiceEvent);
return retVal;
}
Modified: box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp
===================================================================
--- box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp 2007-09-21 22:59:16 UTC (rev 1852)
+++ box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp 2007-09-21 23:03:10 UTC (rev 1853)
@@ -30,6 +30,7 @@
SERVICE_STATUS gServiceStatus;
SERVICE_STATUS_HANDLE gServiceStatusHandle = 0;
HANDLE gStopServiceEvent = 0;
+DWORD gServiceReturnCode = 0;
#define SERVICE_NAME "boxbackup"
@@ -43,7 +44,8 @@
{
char buf[256];
memset(buf, 0, sizeof(buf));
- _snprintf(buf, sizeof(buf)-1, "%s (%d)", s, err);
+ _snprintf(buf, sizeof(buf)-1, "%s: %s", s,
+ GetErrorMessage(err).c_str());
BOX_ERROR(buf);
MessageBox(0, buf, "Error",
MB_OK | MB_SETFOREGROUND | MB_DEFAULT_DESKTOP_ONLY);
@@ -156,14 +158,22 @@
// service is now stopped
gServiceStatus.dwControlsAccepted &=
~(SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
+
gServiceStatus.dwCurrentState = SERVICE_STOPPED;
+
+ if (gServiceReturnCode != 0)
+ {
+ gServiceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR;
+ gServiceStatus.dwServiceSpecificExitCode = gServiceReturnCode;
+ }
+
SetServiceStatus(gServiceStatusHandle, &gServiceStatus);
}
}
-int OurService(char* pConfigFileName)
+int OurService(const char* pConfigFileName)
{
- spConfigFileName = pConfigFileName;
+ spConfigFileName = strdup(pConfigFileName);
SERVICE_TABLE_ENTRY serviceTable[] =
{
@@ -175,6 +185,9 @@
// Register with the SCM
success = StartServiceCtrlDispatcher(serviceTable);
+ free(spConfigFileName);
+ spConfigFileName = NULL;
+
if (!success)
{
ErrorHandler("Failed to start service. Did you start "
@@ -222,7 +235,7 @@
cmd[sizeof(cmd)-1] = 0;
std::string cmdWithArgs(cmd);
- cmdWithArgs += " --service";
+ cmdWithArgs += " -s";
if (pConfigFileName != NULL)
{
Modified: box/chris/general/bin/bbackupd/Win32ServiceFunctions.h
===================================================================
--- box/chris/general/bin/bbackupd/Win32ServiceFunctions.h 2007-09-21 22:59:16 UTC (rev 1852)
+++ box/chris/general/bin/bbackupd/Win32ServiceFunctions.h 2007-09-21 23:03:10 UTC (rev 1853)
@@ -14,6 +14,6 @@
int RemoveService (void);
int InstallService (const char* pConfigFilePath);
-int OurService (char* pConfigFileName);
+int OurService (const char* pConfigFileName);
#endif
More information about the Boxbackup-commit
mailing list