From 3bedf8846f4d7a5cb38276b274662d62a36dcd52 Mon Sep 17 00:00:00 2001 From: Martin Ebourne Date: Mon, 12 Dec 2005 20:50:00 +0000 Subject: Marged chris/win32/merge/07-win32-fixes at r210 to trunk --- bin/bbackupd/bbackupd.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) (limited to 'bin/bbackupd/bbackupd.cpp') diff --git a/bin/bbackupd/bbackupd.cpp b/bin/bbackupd/bbackupd.cpp index ca843105..1c870317 100755 --- a/bin/bbackupd/bbackupd.cpp +++ b/bin/bbackupd/bbackupd.cpp @@ -11,16 +11,84 @@ #include "BackupDaemon.h" #include "MainHelper.h" #include "BoxPortsAndFiles.h" +#include "BackupStoreException.h" #include "MemLeakFindOn.h" +#ifdef WIN32 + #include "Win32ServiceFunctions.h" + #include "Win32BackupService.h" + + extern Win32BackupService gDaemonService; +#endif + int main(int argc, const char *argv[]) { MAINHELPER_START +#ifdef WIN32 + + ::openlog("Box Backup (bbackupd)", 0, 0); + + if(argc == 2 && + (::strcmp(argv[1], "--help") == 0 || + ::strcmp(argv[1], "-h") == 0)) + { + printf("-h help, -i install service, -r remove service,\n" + "-c start daemon now"); + return 2; + } + if(argc == 2 && ::strcmp(argv[1], "-r") == 0) + { + RemoveService(); + return 0; + } + if(argc == 2 && ::strcmp(argv[1], "-i") == 0) + { + InstallService(); + return 0; + } + + // Under win32 we must initialise the Winsock library + // before using sockets + + WSADATA info; + + if (WSAStartup(MAKELONG(1, 1), &info) == SOCKET_ERROR) + { + // box backup will not run without sockets + ::syslog(LOG_ERR, "Failed to initialise Windows Sockets"); + THROW_EXCEPTION(BackupStoreException, Internal) + } + + EnableBackupRights(); + + int ExitCode = 0; + + if (argc == 2 && ::strcmp(argv[1], "--service") == 0) + { + syslog(LOG_INFO,"Starting Box Backup Service"); + OurService(); + } + else + { + ExitCode = gDaemonService.Main( + BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv); + } + + // Clean up our sockets + WSACleanup(); + + ::closelog(); + + return ExitCode; + +#else // !WIN32 + BackupDaemon daemon; return daemon.Main(BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv); - + +#endif // WIN32 + MAINHELPER_END } - -- cgit v1.2.3