diff options
Diffstat (limited to 'bin/bbackupd/bbackupd.cpp')
-rw-r--r-- | bin/bbackupd/bbackupd.cpp | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/bin/bbackupd/bbackupd.cpp b/bin/bbackupd/bbackupd.cpp index e00d3628..089b2d09 100644 --- a/bin/bbackupd/bbackupd.cpp +++ b/bin/bbackupd/bbackupd.cpp @@ -19,7 +19,7 @@ #include "Win32ServiceFunctions.h" #include "Win32BackupService.h" - extern Win32BackupService* gpDaemonService; + extern Win32BackupService gDaemonService; #endif int main(int argc, const char *argv[]) @@ -28,7 +28,7 @@ int main(int argc, const char *argv[]) #ifdef WIN32 - ::openlog("Box Backup (bbackupd)", LOG_PID, LOG_LOCAL6); + ::openlog("Box Backup (bbackupd)", 0, 0); if(argc == 2 && (::strcmp(argv[1], "--help") == 0 || @@ -40,25 +40,32 @@ int main(int argc, const char *argv[]) } if(argc == 2 && ::strcmp(argv[1], "-r") == 0) { - return RemoveService(); + RemoveService(); + return 0; } - if((argc == 2 || argc == 3) && ::strcmp(argv[1], "-i") == 0) + if(argc == 2 && ::strcmp(argv[1], "-i") == 0) { - const char* config = NULL; - if (argc == 3) - { - config = argv[2]; - } - return InstallService(config); + InstallService(); + return 0; } bool runAsWin32Service = false; - if (argc >= 2 && ::strcmp(argv[1], "--service") == 0) + if (argc == 2 && ::strcmp(argv[1], "--service") == 0) { runAsWin32Service = true; } + + // Under win32 we must initialise the Winsock library + // before using sockets + + WSADATA info; - gpDaemonService = new Win32BackupService(); + if (WSAStartup(0x0101, &info) == SOCKET_ERROR) + { + // box backup will not run without sockets + ::syslog(LOG_ERR, "Failed to initialise Windows Sockets"); + THROW_EXCEPTION(BackupStoreException, Internal) + } EnableBackupRights(); @@ -66,32 +73,19 @@ int main(int argc, const char *argv[]) if (runAsWin32Service) { - 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"); + syslog(LOG_INFO,"Starting Box Backup Service"); + OurService(); } else { - ExitCode = gpDaemonService->Main( + ExitCode = gDaemonService.Main( BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv); } - ::closelog(); + // Clean up our sockets + WSACleanup(); - delete gpDaemonService; + ::closelog(); return ExitCode; |