Changeset 353 for box/trunk/lib/server/Daemon.cpp
- Timestamp:
- 30/01/2006 20:04:53 (6 years ago)
- File:
-
- 1 edited
-
box/trunk/lib/server/Daemon.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/lib/server/Daemon.cpp
r217 r353 10 10 #include "Box.h" 11 11 12 #include <errno.h> 12 13 #include <stdio.h> 13 14 #include <unistd.h> … … 16 17 #include <stdarg.h> 17 18 18 #if ndef WIN3219 #include <syslog.h>19 #ifdef HAVE_SYSLOG_H 20 #include <syslog.h> 20 21 #endif 21 22 … … 25 26 #include "Guards.h" 26 27 #include "UnixUser.h" 28 #include "FileModificationTime.h" 27 29 28 30 #include "MemLeakFindOn.h" … … 93 95 94 96 std::string pidFileName; 95 const char *configfile = 0;96 97 97 98 try 98 99 { 99 100 // Find filename of config file 100 configfile = DefaultConfigFile;101 mConfigFileName = DefaultConfigFile; 101 102 if(argc >= 2) 102 103 { … … 104 105 if(::strcmp(argv[1], "-c") == 0 && argc >= 3) 105 106 { 106 configfile = argv[2];107 mConfigFileName = argv[2]; 107 108 } 108 109 else 109 110 { 110 configfile = argv[1];111 mConfigFileName = argv[1]; 111 112 } 112 113 } … … 124 125 // Load the configuration file. 125 126 std::string errors; 126 std::auto_ptr<Configuration> pconfig = Configuration::LoadAndVerify(configfile, GetConfigVerify(), errors); 127 std::auto_ptr<Configuration> pconfig = 128 Configuration::LoadAndVerify( 129 mConfigFileName.c_str(), 130 GetConfigVerify(), errors); 127 131 128 132 // Got errors? … … 130 134 { 131 135 // Tell user about errors 132 fprintf(stderr, "%s: Errors in config file %s:\n%s", DaemonName(), configfile, errors.c_str()); 136 fprintf(stderr, "%s: Errors in config file %s:\n%s", 137 DaemonName(), mConfigFileName.c_str(), 138 errors.c_str()); 133 139 // And give up 134 140 return 1; … … 137 143 // Store configuration 138 144 mpConfiguration = pconfig.release(); 145 mLoadedConfigModifiedTime = GetConfigFileModifiedTime(); 139 146 140 147 // Server configuration … … 229 236 ::openlog(DaemonName(), LOG_PID, LOG_LOCAL6); 230 237 // Log the start message 231 ::syslog(LOG_INFO, "Starting daemon (config: %s) (version " BOX_VERSION ")", configfile); 238 ::syslog(LOG_INFO, "Starting daemon (config: %s) (version " 239 BOX_VERSION ")", mConfigFileName.c_str()); 232 240 233 241 #ifndef WIN32 … … 307 315 { 308 316 // Need to reload that config file... 309 ::syslog(LOG_INFO, "Reloading configuration (config: %s)", configfile); 317 ::syslog(LOG_INFO, "Reloading configuration " 318 "(config: %s)", 319 mConfigFileName.c_str()); 310 320 std::string errors; 311 std::auto_ptr<Configuration> pconfig = Configuration::LoadAndVerify(configfile, GetConfigVerify(), errors); 321 std::auto_ptr<Configuration> pconfig = 322 Configuration::LoadAndVerify( 323 mConfigFileName.c_str(), 324 GetConfigVerify(), errors); 312 325 313 326 // Got errors? … … 315 328 { 316 329 // Tell user about errors 317 ::syslog(LOG_ERR, "Errors in config file %s:\n%s", configfile, errors.c_str()); 330 ::syslog(LOG_ERR, "Errors in config " 331 "file %s:\n%s", 332 mConfigFileName.c_str(), 333 errors.c_str()); 318 334 // And give up 319 335 return 1; … … 326 342 // Store configuration 327 343 mpConfiguration = pconfig.release(); 344 mLoadedConfigModifiedTime = 345 GetConfigFileModifiedTime(); 328 346 329 347 // Stop being marked for loading config again … … 548 566 #endif // HAVE_SETPROCTITLE 549 567 } 568 569 570 // -------------------------------------------------------------------------- 571 // 572 // Function 573 // Name: Daemon::GetConfigFileModifiedTime() 574 // Purpose: Returns the timestamp when the configuration file 575 // was last modified 576 // 577 // Created: 2006/01/29 578 // 579 // -------------------------------------------------------------------------- 580 581 box_time_t Daemon::GetConfigFileModifiedTime() const 582 { 583 struct stat st; 584 585 if(::stat(GetConfigFileName().c_str(), &st) != 0) 586 { 587 if (errno == ENOENT) 588 { 589 return 0; 590 } 591 THROW_EXCEPTION(CommonException, OSFileError) 592 } 593 594 return FileModificationTime(st); 595 } 596 597 // -------------------------------------------------------------------------- 598 // 599 // Function 600 // Name: Daemon::GetLoadedConfigModifiedTime() 601 // Purpose: Returns the timestamp when the configuration file 602 // had been last modified, at the time when it was 603 // loaded 604 // 605 // Created: 2006/01/29 606 // 607 // -------------------------------------------------------------------------- 608 609 box_time_t Daemon::GetLoadedConfigModifiedTime() const 610 { 611 return mLoadedConfigModifiedTime; 612 } 613
Note: See TracChangeset
for help on using the changeset viewer.
