Ignore:
Timestamp:
30/01/2006 20:04:53 (6 years ago)
Author:
ben
Message:

Merge chris/bb-save-state, resolving conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/server/Daemon.cpp

    r217 r353  
    1010#include "Box.h" 
    1111 
     12#include <errno.h> 
    1213#include <stdio.h> 
    1314#include <unistd.h> 
     
    1617#include <stdarg.h> 
    1718 
    18 #ifndef WIN32 
    19 #include <syslog.h> 
     19#ifdef HAVE_SYSLOG_H 
     20        #include <syslog.h> 
    2021#endif 
    2122 
     
    2526#include "Guards.h" 
    2627#include "UnixUser.h" 
     28#include "FileModificationTime.h" 
    2729 
    2830#include "MemLeakFindOn.h" 
     
    9395 
    9496        std::string pidFileName; 
    95         const char *configfile = 0; 
    9697 
    9798        try 
    9899        { 
    99100                // Find filename of config file 
    100                 configfile = DefaultConfigFile; 
     101                mConfigFileName = DefaultConfigFile; 
    101102                if(argc >= 2) 
    102103                { 
     
    104105                        if(::strcmp(argv[1], "-c") == 0 && argc >= 3) 
    105106                        { 
    106                                 configfile = argv[2]; 
     107                                mConfigFileName = argv[2]; 
    107108                        } 
    108109                        else 
    109110                        { 
    110                                 configfile = argv[1]; 
     111                                mConfigFileName = argv[1]; 
    111112                        } 
    112113                } 
     
    124125                // Load the configuration file. 
    125126                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); 
    127131 
    128132                // Got errors? 
     
    130134                { 
    131135                        // 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()); 
    133139                        // And give up 
    134140                        return 1; 
     
    137143                // Store configuration 
    138144                mpConfiguration = pconfig.release(); 
     145                mLoadedConfigModifiedTime = GetConfigFileModifiedTime(); 
    139146                 
    140147                // Server configuration 
     
    229236                ::openlog(DaemonName(), LOG_PID, LOG_LOCAL6); 
    230237                // 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()); 
    232240 
    233241#ifndef WIN32 
     
    307315                        { 
    308316                                // 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()); 
    310320                                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); 
    312325 
    313326                                // Got errors? 
     
    315328                                { 
    316329                                        // 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()); 
    318334                                        // And give up 
    319335                                        return 1; 
     
    326342                                // Store configuration 
    327343                                mpConfiguration = pconfig.release(); 
     344                                mLoadedConfigModifiedTime = 
     345                                        GetConfigFileModifiedTime(); 
    328346                                 
    329347                                // Stop being marked for loading config again 
     
    548566#endif // HAVE_SETPROCTITLE 
    549567} 
     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 
     581box_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 
     609box_time_t Daemon::GetLoadedConfigModifiedTime() const 
     610{ 
     611        return mLoadedConfigModifiedTime; 
     612} 
     613 
Note: See TracChangeset for help on using the changeset viewer.