58 m_log_size (10485760),
60 m_with_log_server (
"no"),
61 m_log_server (
"assalogd@"),
63 m_graceful_quit (
false),
64 m_version (
"unknown"),
66 m_author (
"John Doe"),
67 m_help_msg (
"No help available"),
71 m_ommit_pidfile (
"no"),
74 m_version_flag (
false),
154 std::cerr <<
"Error in arguments: " <<
get_opt_error () << std::endl;
155 std::cerr <<
"Try '" <<
argv[0] <<
" --help' for details.\n";
166 <<
"Written by " <<
m_author <<
"\n\n";
213 if (
m_port.length() == 0) {
234#if !(defined (__FreeBSD__) || defined(__FreeBSD_kernel__) \
235 || defined (__NetBSD__))
273 static const char self[] =
"GenServer::init_internals";
336 DL((
ASSAERR,
"Failed to lock PID file: %s\n",
343 DL((
APP,
"========================================================\n"));
344 DL((
APP,
"|| Server configuration settings ||\n"));
345 DL((
APP,
"========================================================\n"));
352 DL((
APP,
"========================================================\n"));
373 for (
i = 0;
i < size;
i++) {
398 if (
chdir(
"/") == -1 ) {
411 trace(
"GenServer::handle_signal");
412 std::ostringstream
m;
416 case SIGTERM:
m <<
"SIGTERM signal caugth. ";
break;
417 case SIGINT:
m <<
"SIGINT signal caugth. ";
break;
418 default:
m <<
"Unexpected signal caugth.";
420 m <<
"Signal # " <<
signum_ << std::ends;
421 DL((
APP,
"%s\n",
m.str ().c_str () ));
422 DL((
APP,
"Initiating shutdown sequence...\n"));
426 DL((
APP,
"Shutdown sequence completed - Exiting !\n"));
#define ASSA_DIR_SEPARATOR
CommonUtils.h.
GenServer is a base class for generic servers.
#define trace(s)
trace() is used to trace function call chain in C++ program.
#define DL(X)
A macro for writing debug message to the Logger.
A wrapper class to provide AutoPtr with reference semantics.
bool parse_args(const char *argv[])
Parse command line arguments based on installed options set.
bool add_opt(const char c, const string &s, string *str)
Add an option with STL string argument.
bool add_flag_opt(const char c, const string &s, bool *f)
Add binary flag option.
void dump() const
Write options set to the log file.
const char * get_opt_error() const
If previous call to one of member functions returned false, retrieve detailed error message.
Fork class is a simple wrapper around C library function fork().
@ LEAVE_ALONE
Ignore all running children on exit.
@ IGNORE_STATUS
Don't wait for child to complete.
string m_log_server
Log server, assa-logd, address (port@host)
Reactor * get_reactor()
Obtain reference to the Reactor.
string m_author
Author's name.
static bool become_daemon()
Become a daemon process.
string m_cmdline_name
process name as appeared on command line
string get_cmdline_name()
Get command-line process name.
int m_instance
Process instance.
string m_log_file
Full pathname of debug file.
virtual ~GenServer()
Destructor.
PidFileLock m_pidfile_lock
PID File lock.
bool m_graceful_quit
Flag that indicates wheather server outgh to stop and exit.
string m_config_file
alternative configuration file name
void init_internals()
Initialize internals.
string m_ommit_pidfile
If 'yes', skip PID file locking creation/locking step.
string m_pidfile
PID File lock path name.
virtual void display_help()
List options and invocation syntax to stdout.
string m_with_log_server
If 'yes', send log messages to the log server.
bool m_version_flag
Version option flag.
u_int m_log_size
Max size of the log file.
long m_mask
Debug file mask to filter debug/error messages.
string m_log_stdout
If 'yes', redirects all logging messages to std::cerr.
string m_default_config_file
standard configuration file name
SIGPOLLHandler m_sig_poll
Function that swallows SIGPOLL calls.
@ RMLOG
Remove existing log file and start afresh.
string m_port
listening port name
LogFlag m_log_flag
Log file initialization flag. If RM_LOG, remove old log file.
virtual void fatal_signal_hook()
Hook for derived class to do addition clean-up when terminating signal is delivered by OS.
const char * m_help_msg
Help information.
string get_proc_name()
Get name of process+instance_number.
virtual void init(int *argc, char *argv[], const char *help_info)
Provide an entry point into the service and perfom initialization of the service.
string m_proc_name
process name (considering instance_number)
int m_log_level
Logging level - an integer number that incrementally increases verbosity of the looing messages.
int handle_signal(int signum_)
Handle fatal signals.
SigHandlers m_sig_dispatcher
Signal handlers dispatcher.
string get_version()
Obtain version information.
bool m_help_flag
Help option flag.
string m_daemon
Daemon option flag. If 'yes', become a UNIX daemon process.
const char * get_error_msg() const
In case of error, return a verbal description of the last error.
bool lock(const string &filename_)
Lock the file.
void deactivate(void)
Deactivate Reactor.
virtual int install(int signum_, EventHandler *new_hand_, SigAction *new_disp_=0, EventHandler **old_hand_=0, SigAction *old_disp_=0)
Register EventHandler with dispatching system.
int open_log_file(const char *logfname_, u_long groups_=ALL, u_long maxsize_=10485760)
Open log file.
int log_close(void)
Close logging stream.
void set_app_name(const std::string &appname_)
Set application name.
int open_log_server(const std::string &logsvraddr_, const char *logfname_, Reactor *reactor_, u_long groups_=ASSA::ALL, u_long maxsize_=10485760)
Open connection with and write log message to the log server.
int open_log_stdout(u_long groups_=ALL)
Write log message to standard output.
std::string strenv(const char *in_)
Expand the passed string in_ by substituting environment variable names for their values.
@ APP
Application-level messages
@ ASSAERR
ASSA and system errors
@ ALL
All messages: library + application