[Box Backup-commit] COMMIT r1889 - box/trunk/bin/bbackupd
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Wed Oct 17 13:53:30 BST 2007
Author: chris
Date: 2007-10-17 13:53:29 +0100 (Wed, 17 Oct 2007)
New Revision: 1889
Modified:
box/trunk/bin/bbackupd/Win32BackupService.cpp
box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp
box/trunk/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).
(merges [1853])
Modified: box/trunk/bin/bbackupd/Win32BackupService.cpp
===================================================================
--- box/trunk/bin/bbackupd/Win32BackupService.cpp 2007-10-17 12:53:07 UTC (rev 1888)
+++ box/trunk/bin/bbackupd/Win32BackupService.cpp 2007-10-17 12:53:29 UTC (rev 1889)
@@ -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/trunk/bin/bbackupd/Win32ServiceFunctions.cpp
===================================================================
--- box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp 2007-10-17 12:53:07 UTC (rev 1888)
+++ box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp 2007-10-17 12:53:29 UTC (rev 1889)
@@ -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/trunk/bin/bbackupd/Win32ServiceFunctions.h
===================================================================
--- box/trunk/bin/bbackupd/Win32ServiceFunctions.h 2007-10-17 12:53:07 UTC (rev 1888)
+++ box/trunk/bin/bbackupd/Win32ServiceFunctions.h 2007-10-17 12:53:29 UTC (rev 1889)
@@ -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