ASSA::GenServer Class Reference

#include <GenServer.h>

Inheritance diagram for ASSA::GenServer:

ASSA::EventHandler ASSA::CmdLineOpts

List of all members.

Public Types

enum  LogFlag { KEEPLOG, RMLOG }

Public Member Functions

 GenServer ()
 Constructor.
virtual ~GenServer ()
 Destructor.
virtual void init (int *argc, char *argv[], const char *help_info)
 Provide an entry point into the service and perfom initialization of the service.
virtual int fini (void)
 This is an iterface function corresponding to the object moving back into IDLE state.
virtual int suspend (void)
 Temporarily suspend the execution of a service.
virtual int resume (void)
 Resume execution of a service.
virtual void init_service ()=0
 Interface function provided for derived classes as a place to initialize specifics of derived server.
virtual void process_events ()=0
 Interface function provided for derived classes as the main entry for data processing.
virtual void fatal_signal_hook ()
 Hook for derived class to do addition clean-up when terminating signal is delivered by OS.
int handle_signal (int signum_)
 Handle fatal signals.
bool service_is_active ()
 Normally called by the main loop to find out whether 'graceful quit' flag had been raised, signaling that some application's component requested to end data processing.
void stop_service ()
 Inform server that it has to stop data processing, clean up and exit.
void set_version (const string &release_, int revision_)
 Set Version and Revision number.
string get_version ()
 Obtain version information.
void set_author (const string &author_)
 Set author's name.
void set_flags (LogFlag logf_)
 New debug information is added to the old log file.
virtual void display_help ()
 List options and invocation syntax to stdout.
string get_proc_name ()
 Get name of process+instance_number.
void set_proc_name (string proc_name_)
 Change process name.
string get_cmdline_name ()
 Get command-line process name.
string get_default_config_file ()
 Get default configuration file name: $HOME/.
string get_config_file ()
 Get alternative configuration file name.
string get_port ()
 Return assumed name of the listening port.
void set_port (string port_)
 Set listening port name.
SigHandlersget_sig_manager ()
 Obtain reference to the Signal Manager, class SigHandls.
Reactorget_reactor ()
 Obtain reference to the Reactor.
int get_exit_value () const
 Retrieve exit value of the process.

Static Public Member Functions

static bool become_daemon ()
 Become a daemon process.

Protected Member Functions

void set_exit_value (int v_)
 Set exit value of the process. This value is returned to the shell.

Protected Attributes

string m_proc_name
 process name (considering instance_number)
string m_cmdline_name
 process name as appeared on command line
string m_port
 listening port name
string m_default_config_file
 standard configuration file name
string m_config_file
 alternative configuration file name
u_int m_log_size
 Max size of the log file.
int m_instance
 Process instance.
string m_log_file
 Full pathname of debug file.
string m_with_log_server
 If 'yes', send log messages to the log server.
string m_log_server
 Log server, assa-logd, address (port@host).
long m_mask
 Debug file mask to filter debug/error messages.
bool m_graceful_quit
 Flag that indicates wheather server outgh to stop and exit.
SigHandlers m_sig_dispatcher
 Signal handlers dispatcher.
SIGPOLLHandler m_sig_poll
 Function that swallows SIGPOLL calls.
Reactor m_reactor
 GenServer object has its very own personal Reactor object.
string m_version
 Software version.
int m_revision
 Software revision (patch) level.
string m_author
 Author's name.
const char * m_help_msg
 Help information.
LogFlag m_log_flag
 Log file initialization flag. If RM_LOG, remove old log file.
string m_log_stdout
 If 'yes', redirects all logging messages to std::cerr.
string m_daemon
 Daemon option flag. If 'yes', become a UNIX daemon process.
string m_ommit_pidfile
 If 'yes', skip PID file locking creation/locking step.
int m_log_level
 Logging level - an integer number that incrementally increases verbosity of the looing messages.
PidFileLock m_pidfile_lock
 PID File lock.
string m_pidfile
 PID File lock path name.
bool m_help_flag
 Help option flag.
bool m_version_flag
 Version option flag.
int m_exit_value
 Exit value of the process.

Private Member Functions

 GenServer (const GenServer &)
 No cloning.
GenServeroperator= (const GenServer &)
void init_internals ()
 Initialize internals.


Detailed Description

Definition at line 59 of file GenServer.h.


Member Enumeration Documentation

Enumerator:
KEEPLOG  By default, append new log records to the existing log file.

This is operational mode.

RMLOG  Remove existing log file and start afresh.

Convenient during development phase.

Definition at line 66 of file GenServer.h.

00066                  { 
00067         KEEPLOG,                
00070         RMLOG                   
00072     };


Constructor & Destructor Documentation

GenServer::GenServer (  ) 

Constructor.

Corresponds to the object entering the IDLE state.

Form a valid log server address

Definition at line 56 of file GenServer.cpp.

References ASSA::CmdLineOpts::add_flag_opt(), ASSA::CmdLineOpts::add_opt(), m_config_file, m_daemon, m_help_flag, m_instance, m_log_file, m_log_level, m_log_server, m_log_size, m_log_stdout, m_mask, m_ommit_pidfile, m_pidfile, m_port, m_version_flag, and m_with_log_server.

00057     :
00058     m_log_size        (10485760), // 10 Mb 
00059     m_instance        (-1),
00060     m_with_log_server ("no"),
00061     m_log_server      ("assalogd@"),
00062     m_mask            (ALL), 
00063     m_graceful_quit   (false),
00064     m_version         ("unknown"),
00065     m_revision        (0),
00066     m_author          ("John Doe"),
00067     m_help_msg        ("No help available"),
00068     m_log_flag        (KEEPLOG),
00069     m_log_stdout      ("no"),
00070     m_daemon          ("no"),
00071     m_ommit_pidfile   ("no"),
00072     m_log_level       (-1),
00073     m_help_flag       (false),
00074     m_version_flag    (false),
00075     m_exit_value      (0)
00076 {
00077     add_flag_opt ('h', "help",       &m_help_flag);
00078     add_flag_opt ('v', "version",    &m_version_flag);
00079 
00080     add_opt ('d', "log-stdout",      &m_log_stdout);
00081     add_opt ('b', "daemon",          &m_daemon);
00082     add_opt ('L', "ommit-pidfile",   &m_ommit_pidfile);
00083     add_opt ('s', "with-log-server", &m_with_log_server);
00084     add_opt ('m', "mask",            &m_mask);
00085     add_opt ('D', "log-file",        &m_log_file);
00086     add_opt ('f', "config-file",     &m_config_file);
00087     add_opt ('n', "instance",        &m_instance);
00088     add_opt ('p', "port",            &m_port);
00089     add_opt ('z', "log-size",        &m_log_size);
00090     add_opt ('l', "pidfile",         &m_pidfile);
00091     add_opt ('S', "log-server",      &m_log_server);
00092     add_opt ('c', "log-level",       &m_log_level);
00093 
00096     char hn[64];
00097     ::gethostname (hn, sizeof (hn)-1);
00098     m_log_server += hn;
00099 }

GenServer::~GenServer (  )  [virtual]

Destructor.

Reactor needs to *detach* itself from the Logger before releasing memory.

Otherwise, a race condition between Logger (singleton) and GenServer (singleton) might yield core dump if Reactor was destroyed before Logger. Since Reactor is *attached* to the Logger with Logger::log_open () for the assa-logd connection, it is Reactor's responsibility to *detach* first. But, we only care about GenServer's Reactor. All others (such as those used by Connector and Acceptor classes) should not.

Definition at line 112 of file GenServer.cpp.

References ASSA::Log::log_close().

00113 {
00114     Log::log_close ();
00115 }

ASSA::GenServer::GenServer ( const GenServer  )  [private]

No cloning.


Member Function Documentation

void GenServer::init ( int *  argc,
char *  argv[],
const char *  help_info 
) [virtual]

Provide an entry point into the service and perfom initialization of the service.

Open log file and log startup options. Process standard command-line arguments. Following signals are handled in uniform manner: SIGHUP, SIGPIPE, SIGCHLD, SIGCLD, SIGALRM, SIGINT, SIGPOLL, SIGTERM.

This function corresponds to the object moving from IDLE to RUNNING state as result of service initialization, or reconfiguration of the service and remaining in RUNNING state.

Parameters:
argc Pointer to number of command line arguments
argv Command line arguments char* array
help_info Title that will be displayed with -h option

Solaris x86 whole path is returned. Scan through the path and get the process name.

Convert relative paths of all filepath options to absolute paths.

Daemonize the process if asked

Setting defaults if required

Setup signal handling. Ignore SIGHUP, SIGPIPE, SIGCHLD, SIGCLD, SIGALRM by default.

SIGHUP is generated by terminal driver (see termio(7I) for details) in response to modem hangup (or closing terminal session). I ignore it here with the assumption that GenServer is alway a daemon process that doesn't have associated controlling terminal anyway.

Catch SIGPOLL - sigPOLL handler just does nothing except of catching signal.

SIGINT is generated by the terminal driver when an interrupt key is pressed (DELETE or Ctrl-C). It is sent to all processes associated with the controlling terminal. We terminate process in this case.

Catch and handle SIGTERM signals. is the termination signal sent by kill command by default or internally as a part of fatal application exception handling to properly terminate GenServer process.

Initialize other internal stuff.

Definition at line 124 of file GenServer.cpp.

References ASSA_DIR_SEPARATOR, ASSAIOSIG, become_daemon(), display_help(), ASSA::endl(), ASSA::CmdLineOpts::get_opt_error(), get_version(), init_internals(), ASSA::SigHandlers::install(), m_author, m_cmdline_name, m_config_file, m_daemon, m_default_config_file, m_help_flag, m_help_msg, m_instance, m_log_file, m_pidfile, m_port, m_proc_name, m_sig_dispatcher, m_sig_poll, m_version_flag, ASSA::CmdLineOpts::parse_args(), ASSA::SigAction::register_action(), and ASSA::Utils::strenv().

00125 {
00126     char* cp = argv [0];
00127     m_help_msg = ht_;
00128 
00133     if (strchr(cp, ASSA_DIR_SEPARATOR)) {
00134         cp += strlen(argv[0]); // position at the end
00135         while (*cp-- != ASSA_DIR_SEPARATOR) {
00136             ;
00137         }
00138         cp += 2;
00139     }
00140 
00141 #if defined (WIN32)             // get rid of '.exe'
00142     char* extidx = cp;
00143     while (*extidx) {
00144         if (*extidx == '.') {
00145             *extidx = '\0';
00146             break;
00147         }
00148         extidx++;
00149     }
00150 #endif
00151     m_cmdline_name = cp;        
00152     
00153     if (!parse_args ((const char **)argv)) {
00154         std::cerr << "Error in arguments: " << get_opt_error () << std::endl;
00155         std::cerr << "Try '" << argv[0] << " --help' for details.\n";
00156         exit (1);
00157     }
00158 
00159     if (m_help_flag) {
00160         display_help ();
00161         exit (0);
00162     }
00163 
00164     if (m_version_flag) {
00165         std::cerr << '\n' << argv[0] << " " << get_version () << '\n' << '\n'
00166              << "Written by " << m_author << "\n\n";
00167         exit (0);
00168     }
00169 
00173     std::string s;
00174 
00175     if (m_default_config_file.size ()) {
00176         s = ASSA::Utils::strenv (m_default_config_file.c_str ());
00177         m_default_config_file = s;
00178     }
00179 
00180     if (m_config_file.size ()) {
00181         s = ASSA::Utils::strenv (m_config_file.c_str ());
00182         m_config_file = s;
00183     }
00184 
00185     if (m_log_file.size ()) {
00186         s = ASSA::Utils::strenv (m_log_file.c_str ());
00187         m_log_file = s;
00188     }
00189 
00190     if (m_pidfile.size ()) {
00191         s = ASSA::Utils::strenv (m_pidfile.c_str ());
00192         m_pidfile = s;
00193     }
00194 
00197     if (m_daemon == "yes") {
00198         assert(become_daemon ());
00199     }
00200 
00203     char instbuf[16];       // INT_MAX   [-]2147483647
00204     sprintf(instbuf, "%d", m_instance);
00205 
00206     if (m_proc_name.length() == 0) {
00207         m_proc_name = m_cmdline_name;
00208 
00209         if (m_instance != -1) {
00210             m_proc_name += instbuf;
00211         }
00212     }
00213     if (m_port.length() == 0) {
00214         m_port = m_proc_name;
00215     }
00216 
00217 #if !defined(WIN32)
00218 
00221     SigAction ignore_act( SIG_IGN );
00222 
00230     ignore_act.register_action( SIGHUP );
00231     
00232     ignore_act.register_action( SIGPIPE );
00233     ignore_act.register_action( SIGCHLD );
00234 #if !(defined (__FreeBSD__) || defined(__FreeBSD_kernel__) \
00235       || defined (__NetBSD__))
00236     ignore_act.register_action( SIGCLD );
00237 #endif
00238     ignore_act.register_action( SIGALRM );
00239     
00244     m_sig_dispatcher.install ( ASSAIOSIG, &m_sig_poll );
00245 
00252     m_sig_dispatcher.install ( SIGINT, (EventHandler*) this );
00253     
00260     m_sig_dispatcher.install ( SIGTERM, (EventHandler*) this );
00261 
00262 #endif // !defined(WIN32)
00263 
00266     init_internals ();
00267 }

virtual int ASSA::GenServer::fini ( void   )  [inline, virtual]

This is an iterface function corresponding to the object moving back into IDLE state.

Derived class is expected to perform actions that terminate execution of the service.

Definition at line 107 of file GenServer.h.

00107 { return 0; }

virtual int ASSA::GenServer::suspend ( void   )  [inline, virtual]

Temporarily suspend the execution of a service.

Corresponds to process leaving RUNNING state and entering SUSPENDED state.

Definition at line 112 of file GenServer.h.

00112 { return 0; }

virtual int ASSA::GenServer::resume ( void   )  [inline, virtual]

Resume execution of a service.

Corresponds to the process returning back to RUNNING state from SUSPENDED state.

Definition at line 117 of file GenServer.h.

00117 { return 0; }

virtual void ASSA::GenServer::init_service (  )  [pure virtual]

Interface function provided for derived classes as a place to initialize specifics of derived server.

virtual void ASSA::GenServer::process_events (  )  [pure virtual]

Interface function provided for derived classes as the main entry for data processing.

This is the place to implement main event loop.

virtual void ASSA::GenServer::fatal_signal_hook (  )  [inline, virtual]

Hook for derived class to do addition clean-up when terminating signal is delivered by OS.

Note that signal handling is provided by default and no additional intervention is necessary. Use this method only to enhance it.

Definition at line 135 of file GenServer.h.

Referenced by handle_signal().

00135 { /*--- empty ---*/ }

int GenServer::handle_signal ( int  signum_  )  [virtual]

Handle fatal signals.

Hook (e.g. fatalSignalHook) is provided if derived class needs extra work before falling dead.

Reimplemented from ASSA::EventHandler.

Definition at line 409 of file GenServer.cpp.

References ASSA::APP, ASSA::Reactor::deactivate(), DL, ASSA::ends(), fatal_signal_hook(), get_reactor(), m_graceful_quit, and trace.

00410 {
00411     trace("GenServer::handle_signal");
00412     std::ostringstream m;
00413     
00414     switch (signum_) 
00415     {
00416         case SIGTERM: m << "SIGTERM signal caugth. "; break;
00417         case SIGINT:  m << "SIGINT signal caugth. "; break;
00418         default:      m << "Unexpected signal caugth.";
00419     }
00420     m << "Signal # " << signum_ << std::ends;
00421     DL((APP,"%s\n", m.str ().c_str () ));
00422     DL((APP,"Initiating shutdown sequence...\n"));
00423 
00424     fatal_signal_hook ();
00425 
00426     DL((APP, "Shutdown sequence completed - Exiting !\n"));
00427     
00428     /* Calling stop_service () triggers a call to Reactor::stopReactor()
00429        with subsequent call to Reactor::removeIOHandler() and then
00430        EventHandler::handle_close(). If EventHandler is in the middle
00431        of the *slow* system call such as read(2), handle_close() will 
00432        destry EventHandler, and after cotrol is returned from 
00433        GenServer::handle_signal(), *slow* system call is restarted 
00434        and proceeds to operate on the memory that has been deleted already.
00435 
00436        Calling Reactor::deactivate() instead delays memory release.
00437     */
00438     get_reactor()->deactivate ();
00439     m_graceful_quit = true;
00440 
00441     return 0;
00442 }       

bool ASSA::GenServer::service_is_active (  )  [inline]

Normally called by the main loop to find out whether 'graceful quit' flag had been raised, signaling that some application's component requested to end data processing.

Returns:
true when active; false if 'graceful quit' flag has been raised;

Definition at line 149 of file GenServer.h.

References m_graceful_quit.

00149 { return (!m_graceful_quit); }

void ASSA::GenServer::stop_service (  )  [inline]

Inform server that it has to stop data processing, clean up and exit.

This method will also stop internal Reactor.

Definition at line 343 of file GenServer.h.

References ASSA::Reactor::deactivate(), m_graceful_quit, and m_reactor.

00344 {
00345     m_graceful_quit = true; 
00346     m_reactor.deactivate ();
00347 }

void ASSA::GenServer::set_version ( const string &  release_,
int  revision_ 
) [inline]

Set Version and Revision number.

Parameters:
release_ Release number.
revision_ Patch level.

Definition at line 351 of file GenServer.h.

References m_revision, and m_version.

00352 {
00353     m_version = release_;
00354     m_revision = revision_;
00355 }

string ASSA::GenServer::get_version (  )  [inline]

Obtain version information.

Definition at line 366 of file GenServer.h.

References ASSA::ends(), m_revision, and m_version.

Referenced by init().

00367 {
00368     std::ostringstream v;
00369     v << "Version: " <<  m_version << " Revision: " << m_revision << std::ends;
00370     return (v.str ());
00371 }

void ASSA::GenServer::set_author ( const string &  author_  )  [inline]

Set author's name.

Definition at line 359 of file GenServer.h.

References m_author.

00360 {
00361     m_author = author_;
00362 }

void ASSA::GenServer::set_flags ( LogFlag  logf_  )  [inline]

New debug information is added to the old log file.

To erase old log file, set flag to RMLOG.

Parameters:
logf_ Defaulted to KEEPLOG that adds log records to the existing log file; RMLOG - remove existing log file and start afresh.

Definition at line 176 of file GenServer.h.

References m_log_flag.

00176 { m_log_flag = logf_; }

void ASSA::GenServer::display_help (  )  [inline, virtual]

List options and invocation syntax to stdout.

Definition at line 375 of file GenServer.h.

References ASSA::endl(), m_author, and m_help_msg.

Referenced by init().

00376 {
00377     std::cout << m_help_msg << '\n' 
00378               << "Written by " << m_author << "\n" << std::endl;
00379 }

string ASSA::GenServer::get_proc_name (  )  [inline]

Get name of process+instance_number.

Definition at line 182 of file GenServer.h.

References m_proc_name.

Referenced by init_internals().

00182 { return m_proc_name; }

void ASSA::GenServer::set_proc_name ( string  proc_name_  )  [inline]

Change process name.

Parameters:
proc_name_ new process name

Definition at line 187 of file GenServer.h.

References m_proc_name.

00187 { m_proc_name = proc_name_; }

string ASSA::GenServer::get_cmdline_name (  )  [inline]

Get command-line process name.

Definition at line 190 of file GenServer.h.

References m_cmdline_name.

Referenced by init_internals().

00190 { return m_cmdline_name; }

string ASSA::GenServer::get_default_config_file (  )  [inline]

Get default configuration file name: $HOME/.

{command_line_name}.cfg If you want your configuration file name to be different, change the value of m_std_config_name in derived class

Definition at line 198 of file GenServer.h.

References m_default_config_file.

00198 { return m_default_config_file; }

string ASSA::GenServer::get_config_file (  )  [inline]

Get alternative configuration file name.

This name is specified as command-line argument '-f'

Definition at line 203 of file GenServer.h.

References m_config_file.

00203 { return m_config_file; }

string ASSA::GenServer::get_port (  )  [inline]

Return assumed name of the listening port.

Definition at line 206 of file GenServer.h.

References m_port.

00206 { return m_port; }

void ASSA::GenServer::set_port ( string  port_  )  [inline]

Set listening port name.

Parameters:
port_ new listening port name

Definition at line 211 of file GenServer.h.

References m_port.

00211 { m_port = port_; }

SigHandlers& ASSA::GenServer::get_sig_manager (  )  [inline]

Obtain reference to the Signal Manager, class SigHandls.

Definition at line 216 of file GenServer.h.

References m_sig_dispatcher.

00216 { return m_sig_dispatcher; }

Reactor* ASSA::GenServer::get_reactor (  )  [inline]

Obtain reference to the Reactor.

Definition at line 221 of file GenServer.h.

References m_reactor.

Referenced by handle_signal(), and init_internals().

00221 { return &m_reactor; }

bool GenServer::become_daemon (  )  [static]

Become a daemon process.

Definition at line 358 of file GenServer.cpp.

References ASSA::Fork::IGNORE_STATUS, ASSA::Fork::isChild(), and ASSA::Fork::LEAVE_ALONE.

Referenced by init().

00359 {
00360 #if defined(WIN32)
00361     return true;
00362 #else
00363     Fork f (Fork::LEAVE_ALONE, Fork::IGNORE_STATUS);
00364 
00365     if (!f.isChild ()) {    // parent exits
00366         exit (0);
00367     }
00368 
00369     int size = 1024;
00370     int i = 0;
00371     pid_t nullfd;
00372 
00373     for (i = 0; i < size; i++) {
00374         (void) close (i);
00375     }
00376         
00377     nullfd = open ("/dev/null", O_WRONLY | O_CREAT, 0666);
00378     if (nullfd == -1) {
00379         syslog (LOG_ERR,"failed to open \"/dev/null\"");
00380         return false;
00381     }
00382 
00383     (void) dup2 (nullfd, 1);
00384     (void) dup2 (nullfd, 2);
00385     (void) close (nullfd);
00386 
00387     if ( setsid() == -1 ) {
00388         syslog (LOG_ERR,"setsid() failed");
00389         return false;
00390     }
00391 
00392     /*---
00393       Changing to root directory would be the right thing to do for a 
00394       server (so that it wouldn't possibly depend on any mounted file 
00395       systems. But, in practice, it might cause a lot of problems.
00396       ---*/
00397 #if 0
00398     if ( chdir("/") == -1 ) {
00399         return false;
00400     }
00401 #endif
00402     return (true);
00403     
00404 #endif  // defined(WIN32)
00405 }

int ASSA::GenServer::get_exit_value (  )  const [inline]

Retrieve exit value of the process.

Definition at line 227 of file GenServer.h.

References m_exit_value.

00227 { return m_exit_value; }

void ASSA::GenServer::set_exit_value ( int  v_  )  [inline, protected]

Set exit value of the process. This value is returned to the shell.

Definition at line 231 of file GenServer.h.

References m_exit_value.

00231 { m_exit_value = v_; }

GenServer& ASSA::GenServer::operator= ( const GenServer  )  [private]

void GenServer::init_internals (  )  [private]

Initialize internals.

Set standard configuration file name. For POSIX systems, it is $HOME/.procname. For Win32, it is $cwd/procname.ini.

Remove existing log file if requested. Unlinking /dev/null character device and replacing it with a regular file leads to the system crash during consecutive reboots. See also assa/FileLogger.cpp.

Open logging facility:

--log-stdout="yes" takes precedence over --with-log-server="yes" which takes precedence over --log-file=/path/to/log

Definition at line 271 of file GenServer.cpp.

References ASSA::APP, ASSA::ASSAERR, DL, ASSA::CmdLineOpts::dump(), get_cmdline_name(), ASSA::PidFileLock::get_error_msg(), get_proc_name(), get_reactor(), ASSA::PidFileLock::lock(), m_cmdline_name, m_config_file, m_default_config_file, m_log_file, m_log_flag, m_log_server, m_log_size, m_log_stdout, m_mask, m_ommit_pidfile, m_pidfile, m_pidfile_lock, m_proc_name, m_with_log_server, ASSA::Log::open_log_file(), ASSA::Log::open_log_server(), ASSA::Log::open_log_stdout(), RMLOG, ASSA::Log::set_app_name(), ASSA::Utils::strenv(), and trace.

Referenced by init().

00272 {
00273     static const char self[] = "GenServer::init_internals";
00274 
00279 #if defined (WIN32)
00280     m_default_config_file = this->get_cmdline_name () + ".ini";
00281 #else
00282     m_default_config_file = "$HOME/." + this->get_cmdline_name ();
00283     m_default_config_file = Utils::strenv (m_default_config_file.c_str ());
00284 #endif
00285 
00291     if (m_log_flag == RMLOG && m_log_stdout == "no") 
00292     {
00293         struct stat fst;
00294         if (::stat (m_log_file.c_str(), &fst) == 0) 
00295         {
00296             if (S_ISREG (fst.st_mode)) {
00297                 ::unlink (m_log_file.c_str());
00298             }
00299         }
00300     }
00301 
00309     Log::set_app_name (get_proc_name ());
00310 
00311     if (m_log_stdout == "yes") {
00312         Log::open_log_stdout (m_mask);
00313     }
00314     else {
00315         if (m_with_log_server == "yes") {
00316             Log::open_log_server (m_log_server, 
00317                                   m_log_file.c_str(), 
00318                                   get_reactor (), 
00319                                   m_mask, 
00320                                   m_log_size) ;
00321         }
00322         else {
00323             Log::open_log_file (m_log_file.c_str(), m_mask, m_log_size);
00324         }
00325     }
00326     
00327     trace(self);
00328 
00329     if (m_ommit_pidfile == "no") 
00330     {
00331         if (m_pidfile.size () == 0) {
00332             string s ("~/." + m_proc_name + ".pid");
00333             m_pidfile = ASSA::Utils::strenv (s.c_str ());
00334         }
00335         if (! m_pidfile_lock.lock (m_pidfile)) {
00336             DL((ASSAERR,"Failed to lock PID file: %s\n",
00337                 m_pidfile_lock.get_error_msg ()));
00338             exit (1);
00339         }
00340     }
00341 
00342     DL((APP,"\n"                                                        ));
00343     DL((APP,"========================================================\n"));
00344     DL((APP,"||         Server configuration settings              ||\n"));
00345     DL((APP,"========================================================\n"));
00346     DL((APP," cmd_line_name       = '%s'\n", m_cmdline_name.c_str()   ));
00347     DL((APP," name                = '%s'\n", m_proc_name.c_str()      ));
00348     DL((APP," default config file = '%s'\n", m_default_config_file.c_str()));
00349     DL((APP," config file         = '%s'\n", m_config_file.c_str()    ));
00350     DL((APP," mask                = 0x%X\n", m_mask                   ));
00351     dump ();
00352     DL((APP,"========================================================\n"));
00353     DL((APP,"\n"));
00354 }


Member Data Documentation

string ASSA::GenServer::m_proc_name [protected]

process name (considering instance_number)

Definition at line 235 of file GenServer.h.

Referenced by get_proc_name(), init(), init_internals(), and set_proc_name().

string ASSA::GenServer::m_cmdline_name [protected]

process name as appeared on command line

Definition at line 238 of file GenServer.h.

Referenced by get_cmdline_name(), init(), and init_internals().

string ASSA::GenServer::m_port [protected]

listening port name

Definition at line 241 of file GenServer.h.

Referenced by GenServer(), get_port(), init(), and set_port().

standard configuration file name

Definition at line 244 of file GenServer.h.

Referenced by get_default_config_file(), init(), and init_internals().

string ASSA::GenServer::m_config_file [protected]

alternative configuration file name

Definition at line 247 of file GenServer.h.

Referenced by GenServer(), get_config_file(), init(), and init_internals().

Max size of the log file.

Definition at line 250 of file GenServer.h.

Referenced by GenServer(), and init_internals().

int ASSA::GenServer::m_instance [protected]

Process instance.

Definition at line 253 of file GenServer.h.

Referenced by GenServer(), and init().

string ASSA::GenServer::m_log_file [protected]

Full pathname of debug file.

Definition at line 256 of file GenServer.h.

Referenced by GenServer(), init(), and init_internals().

If 'yes', send log messages to the log server.

Definition at line 259 of file GenServer.h.

Referenced by GenServer(), and init_internals().

string ASSA::GenServer::m_log_server [protected]

Log server, assa-logd, address (port@host).

Definition at line 263 of file GenServer.h.

Referenced by GenServer(), and init_internals().

long ASSA::GenServer::m_mask [protected]

Debug file mask to filter debug/error messages.

Definition at line 266 of file GenServer.h.

Referenced by GenServer(), and init_internals().

Flag that indicates wheather server outgh to stop and exit.

Definition at line 269 of file GenServer.h.

Referenced by handle_signal(), service_is_active(), and stop_service().

Signal handlers dispatcher.

Definition at line 273 of file GenServer.h.

Referenced by get_sig_manager(), and init().

Function that swallows SIGPOLL calls.

Definition at line 276 of file GenServer.h.

Referenced by init().

GenServer object has its very own personal Reactor object.

Definition at line 280 of file GenServer.h.

Referenced by get_reactor(), and stop_service().

string ASSA::GenServer::m_version [protected]

Software version.

Definition at line 283 of file GenServer.h.

Referenced by get_version(), and set_version().

int ASSA::GenServer::m_revision [protected]

Software revision (patch) level.

Definition at line 286 of file GenServer.h.

Referenced by get_version(), and set_version().

string ASSA::GenServer::m_author [protected]

Author's name.

Definition at line 289 of file GenServer.h.

Referenced by display_help(), init(), and set_author().

const char* ASSA::GenServer::m_help_msg [protected]

Help information.

Definition at line 292 of file GenServer.h.

Referenced by display_help(), and init().

Log file initialization flag. If RM_LOG, remove old log file.

Definition at line 295 of file GenServer.h.

Referenced by init_internals(), and set_flags().

string ASSA::GenServer::m_log_stdout [protected]

If 'yes', redirects all logging messages to std::cerr.

Definition at line 298 of file GenServer.h.

Referenced by GenServer(), and init_internals().

string ASSA::GenServer::m_daemon [protected]

Daemon option flag. If 'yes', become a UNIX daemon process.

Definition at line 301 of file GenServer.h.

Referenced by GenServer(), and init().

If 'yes', skip PID file locking creation/locking step.

Definition at line 304 of file GenServer.h.

Referenced by GenServer(), and init_internals().

Logging level - an integer number that incrementally increases verbosity of the looing messages.

The exact meaning of each level is application-specific.

Definition at line 310 of file GenServer.h.

Referenced by GenServer().

PID File lock.

Definition at line 313 of file GenServer.h.

Referenced by init_internals().

string ASSA::GenServer::m_pidfile [protected]

PID File lock path name.

Definition at line 316 of file GenServer.h.

Referenced by GenServer(), init(), and init_internals().

bool ASSA::GenServer::m_help_flag [protected]

Help option flag.

If true, [-h, --help] option is being specified on command line.

Definition at line 321 of file GenServer.h.

Referenced by GenServer(), and init().

Version option flag.

If true, [-v, --version] options is being specified on command line.

Definition at line 326 of file GenServer.h.

Referenced by GenServer(), and init().

Exit value of the process.

Definition at line 329 of file GenServer.h.

Referenced by get_exit_value(), and set_exit_value().


The documentation for this class was generated from the following files:

Generated on Fri Mar 21 02:52:26 2008 for libassa by  doxygen 1.5.5