From c16cf90559fad4d8382f3cd3f92ca78f35ed2095 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 17 Oct 2007 12:55:05 +0000 Subject: Use the specified service name when installing and removing the service. Pass the service name on the service command line, and use it for event log messages. (merges [1856]) --- bin/bbackupd/BackupDaemon.cpp | 9 ++++++--- bin/bbackupd/Win32ServiceFunctions.cpp | 14 ++++++++------ bin/bbackupd/Win32ServiceFunctions.h | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) (limited to 'bin/bbackupd') diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp index aaae003d..04502427 100644 --- a/bin/bbackupd/BackupDaemon.cpp +++ b/bin/bbackupd/BackupDaemon.cpp @@ -128,7 +128,8 @@ BackupDaemon::BackupDaemon() #ifdef WIN32 , mInstallService(false), mRemoveService(false), - mRunAsService(false) + mRunAsService(false), + mServiceName("bbackupd") #endif { // Only ever one instance of a daemon @@ -347,14 +348,16 @@ int BackupDaemon::Main(const std::string &rConfigFileName) { if (mInstallService) { - return InstallService(rConfigFileName.c_str()); + return InstallService(rConfigFileName.c_str(), mServiceName); } if (mRemoveService) { - return RemoveService(); + return RemoveService(mServiceName); } + Logging::SetProgramName("Box Backup (" + mServiceName + ")"); + int returnCode; if (mRunAsService) diff --git a/bin/bbackupd/Win32ServiceFunctions.cpp b/bin/bbackupd/Win32ServiceFunctions.cpp index 30b7b9bf..a7bf6bd9 100644 --- a/bin/bbackupd/Win32ServiceFunctions.cpp +++ b/bin/bbackupd/Win32ServiceFunctions.cpp @@ -199,7 +199,7 @@ int OurService(const char* pConfigFileName) return 0; } -int InstallService(const char* pConfigFileName) +int InstallService(const char* pConfigFileName, const std::string& rServiceName) { if (pConfigFileName != NULL) { @@ -235,7 +235,7 @@ int InstallService(const char* pConfigFileName) cmd[sizeof(cmd)-1] = 0; std::string cmdWithArgs(cmd); - cmdWithArgs += " -s"; + cmdWithArgs += " -s -S \"" + rServiceName + "\""; if (pConfigFileName != NULL) { @@ -244,10 +244,12 @@ int InstallService(const char* pConfigFileName) cmdWithArgs += "\""; } + std::string serviceDesc = "Box Backup (" + rServiceName + ")"; + SC_HANDLE newService = CreateService( scm, - SERVICE_NAME, - "Box Backup", + rServiceName.c_str(), + serviceDesc.c_str(), SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, @@ -312,7 +314,7 @@ int InstallService(const char* pConfigFileName) return 0; } -int RemoveService(void) +int RemoveService(const std::string& rServiceName) { SC_HANDLE scm = OpenSCManager(0,0,SC_MANAGER_CREATE_SERVICE); @@ -323,7 +325,7 @@ int RemoveService(void) return 1; } - SC_HANDLE service = OpenService(scm, SERVICE_NAME, + SC_HANDLE service = OpenService(scm, rServiceName.c_str(), SERVICE_ALL_ACCESS|DELETE); DWORD err = GetLastError(); CloseServiceHandle(scm); diff --git a/bin/bbackupd/Win32ServiceFunctions.h b/bin/bbackupd/Win32ServiceFunctions.h index 683cb8a6..e04c368f 100644 --- a/bin/bbackupd/Win32ServiceFunctions.h +++ b/bin/bbackupd/Win32ServiceFunctions.h @@ -12,8 +12,8 @@ #ifndef WIN32SERVICEFUNCTIONS_H #define WIN32SERVICEFUNCTIONS_H -int RemoveService (void); -int InstallService (const char* pConfigFilePath); +int RemoveService (const std::string& rServiceName); +int InstallService (const char* pConfigFilePath, const std::string& rServiceName); int OurService (const char* pConfigFileName); #endif -- cgit v1.2.3