diff options
Diffstat (limited to 'bin/bbackupd/Win32BackupService.cpp')
-rw-r--r-- | bin/bbackupd/Win32BackupService.cpp | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/bin/bbackupd/Win32BackupService.cpp b/bin/bbackupd/Win32BackupService.cpp index aa3bf55c..7cbf4828 100644 --- a/bin/bbackupd/Win32BackupService.cpp +++ b/bin/bbackupd/Win32BackupService.cpp @@ -12,40 +12,51 @@ #include "Win32BackupService.h" -Win32BackupService gDaemonService; +Win32BackupService* gpDaemonService = NULL; extern HANDLE gStopServiceEvent; unsigned int WINAPI RunService(LPVOID lpParameter) { - DWORD retVal = gDaemonService.WinService(); - SetEvent( gStopServiceEvent ); + DWORD retVal = gpDaemonService->WinService((const char*) lpParameter); + SetEvent(gStopServiceEvent); return retVal; } void TerminateService(void) { - gDaemonService.SetTerminateWanted(); + gpDaemonService->SetTerminateWanted(); } -DWORD Win32BackupService::WinService(void) +DWORD Win32BackupService::WinService(const char* pConfigFileName) { - int argc = 2; - //first off get the path name for the default - char buf[MAX_PATH]; - - GetModuleFileName(NULL, buf, sizeof(buf)); - std::string buffer(buf); - std::string conf( "-c"); - std::string cfile(buffer.substr(0,(buffer.find("bbackupd.exe"))) - + "bbackupd.conf"); + char exepath[MAX_PATH]; + GetModuleFileName(NULL, exepath, sizeof(exepath)); - const char *argv[] = {conf.c_str(), cfile.c_str()}; + std::string configfile; + + if (pConfigFileName != NULL) + { + configfile = pConfigFileName; + } + else + { + // make the default config file name, + // based on the program path + configfile = exepath; + configfile = configfile.substr(0, + configfile.rfind(DIRECTORY_SEPARATOR_ASCHAR)); + configfile += DIRECTORY_SEPARATOR "bbackupd.conf"; + } + + const char *argv[] = {exepath, "-c", configfile.c_str()}; + int argc = sizeof(argv) / sizeof(*argv); + DWORD ret; MAINHELPER_START - - return this->Main(BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv); - + ret = this->Main(BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv); MAINHELPER_END + + return ret; } #endif // WIN32 |