Changeset 2177
- Timestamp:
- 28/05/2008 14:28:16 (2 years ago)
- Location:
- box/trunk/lib/server
- Files:
-
- 2 modified
-
Daemon.cpp (modified) (7 diffs)
-
Daemon.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/lib/server/Daemon.cpp
r2131 r2177 113 113 "DFkP" 114 114 #endif 115 "hq vVt:TU";115 "hqt:TUvVW:"; 116 116 } 117 117 … … 138 138 " -v Run more verbosely, increase verbosity level by one, can repeat\n" 139 139 " -V Run at maximum verbosity\n" 140 " -W <level> Set verbosity to error/warning/notice/info/trace/everything\n" 140 141 " -t <tag> Tag console output with specified marker\n" 141 142 " -T Timestamp console output\n" … … 235 236 { 236 237 mLogLevel = Log::EVERYTHING; 238 } 239 break; 240 241 case 'W': 242 { 243 mLogLevel = Logging::GetNamedLevel(optarg); 244 if (mLogLevel == Log::INVALID) 245 { 246 BOX_FATAL("Invalid logging level"); 247 return 2; 248 } 237 249 } 238 250 break; … … 354 366 // 355 367 // Function 368 // Name: Daemon::Configure(const std::string& rConfigFileName) 369 // Purpose: Loads daemon configuration. Useful when you have 370 // a local Daemon object and don't intend to fork() 371 // or call Main(). 372 // Created: 2008/04/19 373 // 374 // -------------------------------------------------------------------------- 375 376 bool Daemon::Configure(const std::string& rConfigFileName) 377 { 378 mConfigFileName = rConfigFileName; 379 380 // Load the configuration file. 381 std::string errors; 382 std::auto_ptr<Configuration> pconfig; 383 384 try 385 { 386 pconfig = Configuration::LoadAndVerify( 387 mConfigFileName.c_str(), 388 GetConfigVerify(), errors); 389 } 390 catch(BoxException &e) 391 { 392 if(e.GetType() == CommonException::ExceptionType && 393 e.GetSubType() == CommonException::OSFileOpenError) 394 { 395 BOX_ERROR("Failed to open configuration file: " 396 << mConfigFileName); 397 return false; 398 } 399 400 throw; 401 } 402 403 // Got errors? 404 if(pconfig.get() == 0 || !errors.empty()) 405 { 406 BOX_ERROR("Configuration errors: " << errors); 407 return false; 408 } 409 410 // Store configuration 411 mpConfiguration = pconfig.release(); 412 mLoadedConfigModifiedTime = GetConfigFileModifiedTime(); 413 414 // Let the derived class have a go at setting up stuff 415 // in the initial process 416 SetupInInitialProcess(); 417 418 return true; 419 } 420 421 // -------------------------------------------------------------------------- 422 // 423 // Function 356 424 // Name: Daemon::Main(const std::string& rConfigFileName) 357 425 // Purpose: Starts the daemon off -- equivalent of C main() function … … 368 436 std::string pidFileName; 369 437 370 mConfigFileName = rConfigFileName; 371 372 bool asDaemon = !mSingleProcess && !mRunInForeground; 438 bool asDaemon = !mSingleProcess && !mRunInForeground; 373 439 374 440 try 375 441 { 376 // Load the configuration file. 377 std::string errors; 378 std::auto_ptr<Configuration> pconfig; 379 380 try 381 { 382 pconfig = Configuration::LoadAndVerify( 383 mConfigFileName.c_str(), 384 GetConfigVerify(), errors); 385 } 386 catch(BoxException &e) 387 { 388 if(e.GetType() == CommonException::ExceptionType && 389 e.GetSubType() == CommonException::OSFileOpenError) 390 { 391 BOX_FATAL("Failed to start: failed to open " 392 "configuration file: " 393 << mConfigFileName); 394 return 1; 395 } 396 397 throw; 398 } 399 400 // Got errors? 401 if(pconfig.get() == 0 || !errors.empty()) 402 { 403 // Tell user about errors 404 BOX_FATAL("Failed to start: errors in configuration " 405 "file: " << mConfigFileName << ": " << errors); 406 // And give up 442 if (!Configure(rConfigFileName)) 443 { 444 BOX_FATAL("Failed to start: failed to load " 445 "configuration file: " << rConfigFileName); 407 446 return 1; 408 447 } 409 410 // Store configuration411 mpConfiguration = pconfig.release();412 mLoadedConfigModifiedTime = GetConfigFileModifiedTime();413 414 // Let the derived class have a go at setting up stuff in the initial process415 SetupInInitialProcess();416 448 417 449 // Server configuration … … 676 708 #ifdef WIN32 677 709 WSACleanup(); 710 #else 711 // Should clean up here, but it breaks memory leak tests. 712 /* 713 if(asDaemon) 714 { 715 // we are running in the child by now, and should not return 716 delete mpConfiguration; 717 mpConfiguration = NULL; 718 exit(0); 719 } 720 */ 678 721 #endif 679 722 680 723 return retcode; 681 724 } … … 841 884 // Function 842 885 // Name: Daemon::SetupInInitialProcess() 843 // Purpose: A chance for the daemon to do something initial setting up in the process which 844 // initiates everything, and after the configuration file has been read and verified. 886 // Purpose: A chance for the daemon to do something initial 887 // setting up in the process which initiates 888 // everything, and after the configuration file has 889 // been read and verified. 845 890 // Created: 2003/08/20 846 891 // -
box/trunk/lib/server/Daemon.h
r2127 r2177 55 55 virtual const ConfigurationVerify *GetConfigVerify() const; 56 56 virtual void Usage(); 57 57 58 virtual bool Configure(const std::string& rConfigFileName); 59 58 60 bool StopRun() {return mReloadConfigWanted | mTerminateWanted;} 59 61 bool IsReloadConfigWanted() {return mReloadConfigWanted;} … … 64 66 void SetTerminateWanted() {mTerminateWanted = true;} 65 67 66 virtual void SetupInInitialProcess();67 68 virtual void EnterChild(); 68 69 … … 70 71 71 72 protected: 73 virtual void SetupInInitialProcess(); 72 74 box_time_t GetLoadedConfigModifiedTime() const; 73 75 bool IsSingleProcess() { return mSingleProcess; }
