[Box Backup-dev] COMMIT r788 - box/trunk/bin/bbackupd
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Sun, 20 Aug 2006 00:34:11 +0100
Author: chris
Date: 2006-08-20 00:34:11 +0100 (Sun, 20 Aug 2006)
New Revision: 788
Modified:
box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp
box/trunk/bin/bbackupd/Win32ServiceFunctions.h
box/trunk/bin/bbackupd/bbackupd.cpp
Log:
* bin/bbackupd/Win32ServiceFunctions.h
* bin/bbackupd/Win32ServiceFunctions.cpp
- InstallService() and OurService() take the config file name as a
parameter
- InstallService() returns an integer status code like RemoveService()
- OurService() sets the global static config file name to pass into
the main thread later
* bin/bbackupd/bbackupd.cpp
- Call InstallService() and OurService() with the config file name as a
parameter
Modified: box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp
===================================================================
--- box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp 2006-08-19 17:32:55 UTC (rev 787)
+++ box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp 2006-08-19 23:34:11 UTC (rev 788)
@@ -161,8 +161,10 @@
}
}
-void OurService(void)
+void OurService(char* pConfigFileName)
{
+ spConfigFileName = pConfigFileName;
+
SERVICE_TABLE_ENTRY serviceTable[] =
{
{ SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION) ServiceMain },
@@ -181,7 +183,7 @@
}
}
-void InstallService(void)
+int InstallService(const char* pConfigFileName)
{
SC_HANDLE newService, scm;
@@ -191,7 +193,7 @@
{
syslog(LOG_ERR, "Failed to open service control manager: "
"error %d", GetLastError());
- return;
+ return 1;
}
char cmd[MAX_PATH];
@@ -217,7 +219,7 @@
{
::syslog(LOG_ERR, "Failed to create Box Backup service: "
"error %d", GetLastError());
- return;
+ return 1;
}
::syslog(LOG_INFO, "Created Box Backup service");
@@ -234,6 +236,8 @@
CloseServiceHandle(newService);
CloseServiceHandle(scm);
+
+ return 0;
}
int RemoveService(void)
Modified: box/trunk/bin/bbackupd/Win32ServiceFunctions.h
===================================================================
--- box/trunk/bin/bbackupd/Win32ServiceFunctions.h 2006-08-19 17:32:55 UTC (rev 787)
+++ box/trunk/bin/bbackupd/Win32ServiceFunctions.h 2006-08-19 23:34:11 UTC (rev 788)
@@ -12,8 +12,8 @@
#ifndef WIN32SERVICEFUNCTIONS_H
#define WIN32SERVICEFUNCTIONS_H
-int RemoveService(void);
-void InstallService(void);
-void OurService(void);
+int RemoveService (void);
+int InstallService (const char* pConfigFilePath);
+void OurService (char* pConfigFileName);
#endif
Modified: box/trunk/bin/bbackupd/bbackupd.cpp
===================================================================
--- box/trunk/bin/bbackupd/bbackupd.cpp 2006-08-19 17:32:55 UTC (rev 787)
+++ box/trunk/bin/bbackupd/bbackupd.cpp 2006-08-19 23:34:11 UTC (rev 788)
@@ -43,14 +43,19 @@
RemoveService();
return 0;
}
- if(argc == 2 && ::strcmp(argv[1], "-i") == 0)
+ if((argc == 2 || argc == 3) && ::strcmp(argv[1], "-i") == 0)
{
- InstallService();
+ const char* config = NULL;
+ if (argc == 3)
+ {
+ config = argv[2];
+ }
+ InstallService(config);
return 0;
}
bool runAsWin32Service = false;
- if (argc == 2 && ::strcmp(argv[1], "--service") == 0)
+ if (argc >= 2 && ::strcmp(argv[1], "--service") == 0)
{
runAsWin32Service = true;
}
@@ -73,8 +78,22 @@
if (runAsWin32Service)
{
- syslog(LOG_INFO,"Starting Box Backup Service");
- OurService();
+ syslog(LOG_INFO, "Box Backup service starting");
+
+ char* config = NULL;
+ if (argc >= 3)
+ {
+ config = strdup(argv[2]);
+ }
+
+ OurService(config);
+
+ if (config)
+ {
+ free(config);
+ }
+
+ syslog(LOG_INFO, "Box Backup service shut down");
}
else
{