1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// --------------------------------------------------------------------------
//
// File
// Name: bbackupd.cpp
// Purpose: main file for backup daemon
// Created: 2003/10/11
//
// --------------------------------------------------------------------------
#include "Box.h"
#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
}
|