summaryrefslogtreecommitdiff
path: root/bin/bbackupd/bbackupd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bin/bbackupd/bbackupd.cpp')
-rwxr-xr-xbin/bbackupd/bbackupd.cpp72
1 files changed, 70 insertions, 2 deletions
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 <config file> 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
}
-