Changeset 1854
- Timestamp:
- 22/09/2007 00:05:25 (4 years ago)
- Location:
- box/chris/general/bin/bbackupd
- Files:
-
- 3 edited
-
BackupDaemon.cpp (modified) (3 diffs)
-
BackupDaemon.h (modified) (2 diffs)
-
bbackupd.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
box/chris/general/bin/bbackupd/BackupDaemon.cpp
r1831 r1854 77 77 #include "autogen_ClientException.h" 78 78 79 #ifdef WIN32 80 #include "Win32ServiceFunctions.h" 81 #include "Win32BackupService.h" 82 83 extern Win32BackupService* gpDaemonService; 84 #endif 85 79 86 #include "MemLeakFindOn.h" 80 87 … … 117 124 mDeleteUnusedRootDirEntriesAfter(0), 118 125 mLogAllFileAccess(false) 126 #ifdef WIN32 127 , mInstallService(false), 128 mRemoveService(false), 129 mRunAsService(false) 130 #endif 119 131 { 120 132 // Only ever one instance of a daemon … … 277 289 278 290 #ifdef WIN32 291 std::string BackupDaemon::GetOptionString() 292 { 293 std::string oldOpts = this->Daemon::GetOptionString(); 294 ASSERT(oldOpts.find("s") == std::string::npos); 295 ASSERT(oldOpts.find("S") == std::string::npos); 296 ASSERT(oldOpts.find("i") == std::string::npos); 297 ASSERT(oldOpts.find("r") == std::string::npos); 298 return oldOpts + "sS:ir"; 299 } 300 301 int BackupDaemon::ProcessOption(signed int option) 302 { 303 switch(option) 304 { 305 case 's': 306 { 307 mRunAsService = true; 308 return 0; 309 } 310 311 case 'S': 312 { 313 mServiceName = optarg; 314 return 0; 315 } 316 317 case 'i': 318 { 319 mInstallService = true; 320 return 0; 321 } 322 323 case 'r': 324 { 325 mRemoveService = true; 326 return 0; 327 } 328 329 default: 330 { 331 return this->Daemon::ProcessOption(option); 332 } 333 } 334 } 335 336 int BackupDaemon::Main(const std::string &rConfigFileName) 337 { 338 if (mInstallService) 339 { 340 return InstallService(rConfigFileName.c_str()); 341 } 342 343 if (mRemoveService) 344 { 345 return RemoveService(); 346 } 347 348 int returnCode; 349 350 if (mRunAsService) 351 { 352 // We will be called reentrantly by the Service Control 353 // Manager, and we had better not call OurService again! 354 mRunAsService = false; 355 356 BOX_INFO("Box Backup service starting"); 357 returnCode = OurService(rConfigFileName.c_str()); 358 BOX_INFO("Box Backup service shut down"); 359 } 360 else 361 { 362 returnCode = this->Daemon::Main(rConfigFileName); 363 } 364 365 return returnCode; 366 } 367 279 368 void BackupDaemon::RunHelperThread(void) 280 369 { -
box/chris/general/bin/bbackupd/BackupDaemon.h
r1805 r1854 59 59 bool DeleteStoreObjectInfo() const; 60 60 BackupDaemon(const BackupDaemon &); 61 61 62 public: 63 #ifdef WIN32 64 // add command-line options to handle Windows services 65 std::string GetOptionString(); 66 int ProcessOption(signed int option); 67 int Main(const std::string &rConfigFileName); 68 #endif 62 69 63 70 void Run(); … … 417 424 private: 418 425 bool mDoSyncFlagOut, mSyncIsForcedOut; 426 bool mInstallService, mRemoveService, mRunAsService; 427 std::string mServiceName; 419 428 HANDLE mhMessageToSendEvent, mhCommandReceivedEvent; 420 429 CRITICAL_SECTION mMessageQueueLock; -
box/chris/general/bin/bbackupd/bbackupd.cpp
r1813 r1854 36 36 #ifdef WIN32 37 37 38 if(argc == 2 && 39 (::strcmp(argv[1], "--help") == 0 || 40 ::strcmp(argv[1], "-h") == 0)) 41 { 42 printf("-h help, -i install service, -r remove service,\n" 43 "-c <config file> start daemon now"); 44 return 2; 45 } 46 if(argc == 2 && ::strcmp(argv[1], "-r") == 0) 47 { 48 return RemoveService(); 49 } 50 if((argc == 2 || argc == 3) && ::strcmp(argv[1], "-i") == 0) 51 { 52 const char* config = NULL; 53 if (argc == 3) 54 { 55 config = argv[2]; 56 } 57 return InstallService(config); 58 } 59 60 bool runAsWin32Service = false; 61 if (argc >= 2 && ::strcmp(argv[1], "--service") == 0) 62 { 63 runAsWin32Service = true; 64 } 38 EnableBackupRights(); 65 39 66 40 gpDaemonService = new Win32BackupService(); 67 68 EnableBackupRights(); 69 70 if (runAsWin32Service) 71 { 72 BOX_INFO("Box Backup service starting"); 73 74 char* config = NULL; 75 if (argc >= 3) 76 { 77 config = strdup(argv[2]); 78 } 79 80 ExitCode = OurService(config); 81 82 if (config) 83 { 84 free(config); 85 } 86 87 BOX_INFO("Box Backup service shut down"); 88 } 89 else 90 { 91 ExitCode = gpDaemonService->Main( 92 BOX_GET_DEFAULT_BBACKUPD_CONFIG_FILE, argc, argv); 93 } 94 41 ExitCode = gpDaemonService->Daemon::Main( 42 BOX_GET_DEFAULT_BBACKUPD_CONFIG_FILE, 43 argc, argv); 95 44 delete gpDaemonService; 96 45
Note: See TracChangeset
for help on using the changeset viewer.
