Ignore:
Timestamp:
22/09/2007 00:05:25 (5 years ago)
Author:
chris
Message:

Use Daemon's delegated option processing instead of our own hacks.

Move Windows service startup, installation and removal to BackupDaemon?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/chris/general/bin/bbackupd/BackupDaemon.cpp

    r1831 r1854  
    7777#include "autogen_ClientException.h" 
    7878 
     79#ifdef WIN32 
     80        #include "Win32ServiceFunctions.h" 
     81        #include "Win32BackupService.h" 
     82 
     83        extern Win32BackupService* gpDaemonService; 
     84#endif 
     85 
    7986#include "MemLeakFindOn.h" 
    8087 
     
    117124          mDeleteUnusedRootDirEntriesAfter(0), 
    118125          mLogAllFileAccess(false) 
     126        #ifdef WIN32 
     127        , mInstallService(false), 
     128          mRemoveService(false), 
     129          mRunAsService(false) 
     130        #endif 
    119131{ 
    120132        // Only ever one instance of a daemon 
     
    277289 
    278290#ifdef WIN32 
     291std::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 
     301int 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 
     336int 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 
    279368void BackupDaemon::RunHelperThread(void) 
    280369{ 
Note: See TracChangeset for help on using the changeset viewer.