summaryrefslogtreecommitdiff
path: root/bin/bbackupd/Win32ServiceFunctions.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2007-10-17 12:53:29 +0000
committerChris Wilson <chris+github@qwirx.com>2007-10-17 12:53:29 +0000
commit213ee3a965d0b0dcba7207917ad7654d31d01edf (patch)
treeb264ad9df54b1d0e5d188baea1fdce2179d4e574 /bin/bbackupd/Win32ServiceFunctions.cpp
parent10d5c119ea513a17ad9fad2c65942d482aa317dd (diff)
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])
Diffstat (limited to 'bin/bbackupd/Win32ServiceFunctions.cpp')
-rw-r--r--bin/bbackupd/Win32ServiceFunctions.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/bin/bbackupd/Win32ServiceFunctions.cpp b/bin/bbackupd/Win32ServiceFunctions.cpp
index 5acf5f67..30b7b9bf 100644
--- a/bin/bbackupd/Win32ServiceFunctions.cpp
+++ b/bin/bbackupd/Win32ServiceFunctions.cpp
@@ -30,6 +30,7 @@ TCHAR* gServiceName = TEXT("Box Backup Service");
SERVICE_STATUS gServiceStatus;
SERVICE_STATUS_HANDLE gServiceStatusHandle = 0;
HANDLE gStopServiceEvent = 0;
+DWORD gServiceReturnCode = 0;
#define SERVICE_NAME "boxbackup"
@@ -43,7 +44,8 @@ void ErrorHandler(char *s, DWORD err)
{
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 @@ VOID ServiceMain(DWORD argc, LPTSTR *argv)
// 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 @@ int OurService(char* pConfigFileName)
// 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 @@ int InstallService(const char* pConfigFileName)
cmd[sizeof(cmd)-1] = 0;
std::string cmdWithArgs(cmd);
- cmdWithArgs += " --service";
+ cmdWithArgs += " -s";
if (pConfigFileName != NULL)
{