dnxClientMain.c File Reference

Main source file for DNX Client. More...

#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxTransport.h"
#include "dnxClntProt.h"
#include "dnxCfgParser.h"
#include "dnxWLM.h"
#include "dnxPlugin.h"
#include "dnxLogging.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/file.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <pthread.h>
#include <fcntl.h>
#include <errno.h>
#include <pwd.h>
#include <grp.h>

Go to the source code of this file.

Data Structures

struct  DnxCfgData
 The internal server module configuration data structure. More...

Defines

#define VERSION   "<unknown>"
#define PACKAGE_BUGREPORT   "<unknown>"
#define SYSCONFDIR   "/etc"
#define SYSLOGDIR   "/var/log"
#define SYSRUNPATH   "/var/run/dnx"
#define LIBEXECDIR   "/usr/lib"
#define DNXUSER   "nagios"
#define DNXGROUP   "nagios"
#define COMPILE_FLAGS   "<unknown>"
#define DNX_DEFAULT_NODE_CONFIG_FILE   SYSCONFDIR "/dnxClient.cfg"
#define DNX_DEFAULT_LOG   SYSLOGDIR "/dnxcld.log"
#define DNX_DEFAULT_DBGLOG   SYSLOGDIR "/dnxcld.debug.log"
#define DNX_DEFAULT_PLUGIN_PATH   LIBEXECDIR
#define DNX_DEFAULT_RUN_PATH   SYSRUNPATH
#define DNX_DEFAULT_USER   DNXUSER
#define DNX_DEFAULT_GROUP   DNXGROUP
#define elemcount(x)   (sizeof(x)/sizeof(*(x)))
#define OL_CFGFILE
#define OL_LOGFILE
#define OL_DBGFILE
#define OL_DBGLEVEL
#define OL_DEBUG
#define OL_RUNPATH
#define OL_USER
#define OL_GROUP
#define OL_VERSION
#define OL_HELP

Functions

static char * versionText (char *base)
 Format version text to an allocated string buffer.
static void version (FILE *fp, char *base)
 Display program version information to a specified stream.
static void usage (char *base)
 Display program usage text to STDERR and exit with an error.
static int appendString (char **spp, char *fmt,...)
 Append text to a string by reallocating the string buffer.
static int getOptions (int argc, char **argv)
 Parse command line options.
static int validateCfg (DnxCfgDict *dict, void **vptrs, void *passthru)
 Validate a configuration data structure in context.
static void releaseConfig (void)
 Cleanup the config file parser.
static int initConfig (char *cfgfile)
 Read and parse the dnxClient configuration file.
static int initClientComm (void)
 Initializes a client communication channels and sub-systems.
static void releaseClientComm (void)
 Release resources associated with the client communications sub-system.
static void sighandler (int sig)
 The global signal handler for the dnxClient process.
static int createPidFile (char *base)
 Create the process id (pid) lock file.
static void removePidFile (char *base)
 Remove an existing process id (pid) lock file.
static int daemonize (char *base)
 Turn this process into a daemon.
static int dropPrivileges (void)
 Drop privileges to configured user and group.
static void logGblConfigChanges (DnxCfgData *ocp, DnxCfgData *ncp)
 Log changes between old and new global configuration data sets.
static char * buildHelpReply (void)
 Build an allocated response buffer for the HELP request.
static char * buildMgmtStatsReply (char *req)
 Build an allocated response buffer for requested stats values.
static char * buildMgmtCfgReply (void)
 Build an allocated response buffer for the current configuration.
static void freeCfgData (DnxCfgData *cpy)
 Release a previously copied configuration data structure.
static DnxCfgDatacopyCfgData (DnxCfgData *org)
 Make a dynamic copy of all configuration data.
static int processCommands (void)
 The main event loop for the dnxClient process.
int main (int argc, char **argv)
 The main program entry point for the dnxClient service.

Variables

static DnxCfgData s_cfg
 The system configuration parameters.
static DnxCfgParsers_parser
 The system configuration parser.
static DnxWlms_wlm = 0
 The system worker thread pool.
static DnxChannels_agent
 The agent management channel.
static char * s_progname
 The base program name.
static char * s_cfgfile
 The system configuration file name.
static char * s_cmdover = 0
 The command line overrides string.
static int s_dbgflag = 0
 The system debug flag.
static int s_shutdown = 0
 The shutdown signal flag.
static int s_reconfig = 0
 The reconfigure signal flag.
static int s_debugsig = 0
 The debug toggle signal flag.
static int s_lockfd = -1
 The system PID file descriptor.


Detailed Description

Main source file for DNX Client.

Author:
Robert W. Ingraham (dnx-devel@lists.sourceforge.net)
Attention:
Please submit patches to http://dnx.sourceforge.net

Definition in file dnxClientMain.c.


Define Documentation

#define COMPILE_FLAGS   "<unknown>"

Definition at line 95 of file dnxClientMain.c.

#define DNX_DEFAULT_DBGLOG   SYSLOGDIR "/dnxcld.debug.log"

Definition at line 101 of file dnxClientMain.c.

Referenced by initConfig(), and versionText().

#define DNX_DEFAULT_GROUP   DNXGROUP

Definition at line 105 of file dnxClientMain.c.

Referenced by initConfig(), and versionText().

#define DNX_DEFAULT_LOG   SYSLOGDIR "/dnxcld.log"

Definition at line 100 of file dnxClientMain.c.

Referenced by initConfig(), and versionText().

#define DNX_DEFAULT_NODE_CONFIG_FILE   SYSCONFDIR "/dnxClient.cfg"

Definition at line 99 of file dnxClientMain.c.

Referenced by getOptions(), and versionText().

#define DNX_DEFAULT_PLUGIN_PATH   LIBEXECDIR

Definition at line 102 of file dnxClientMain.c.

Referenced by initConfig().

#define DNX_DEFAULT_RUN_PATH   SYSRUNPATH

Definition at line 103 of file dnxClientMain.c.

Referenced by initConfig(), and versionText().

#define DNX_DEFAULT_USER   DNXUSER

Definition at line 104 of file dnxClientMain.c.

Referenced by initConfig(), and versionText().

#define DNXGROUP   "nagios"

Definition at line 91 of file dnxClientMain.c.

#define DNXUSER   "nagios"

Definition at line 87 of file dnxClientMain.c.

#define elemcount (  )     (sizeof(x)/sizeof(*(x)))

#define LIBEXECDIR   "/usr/lib"

Definition at line 83 of file dnxClientMain.c.

#define OL_CFGFILE

Referenced by usage().

#define OL_DBGFILE

Referenced by usage().

#define OL_DBGLEVEL

Referenced by usage().

#define OL_DEBUG

Referenced by usage().

#define OL_GROUP

Referenced by usage().

#define OL_HELP

Referenced by usage().

#define OL_LOGFILE

Referenced by usage().

#define OL_RUNPATH

Referenced by usage().

#define OL_USER

Referenced by usage().

#define OL_VERSION

Referenced by usage().

#define PACKAGE_BUGREPORT   "<unknown>"

Definition at line 62 of file dnxClientMain.c.

Referenced by main(), and versionText().

#define SYSCONFDIR   "/etc"

Definition at line 71 of file dnxClientMain.c.

#define SYSLOGDIR   "/var/log"

Definition at line 75 of file dnxClientMain.c.

#define SYSRUNPATH   "/var/run/dnx"

Definition at line 79 of file dnxClientMain.c.

#define VERSION   "<unknown>"

Definition at line 61 of file dnxClientMain.c.

Referenced by main(), nebmodule_init(), and versionText().


Function Documentation

static int appendString ( char **  spp,
char *  fmt,
  ... 
) [static]

Append text to a string by reallocating the string buffer.

This is a var-args function. Additional parameters following the fmt parameter are based on the content of the fmt string.

Parameters:
[in] spp - the address of a dynamically allocated buffer pointer.
[in] fmt - a printf-like format specifier string.
Returns:
Zero on success, or DNX_ERR_MEMORY on out-of-memory condition.

Definition at line 260 of file dnxClientMain.c.

References DNX_ERR_MEMORY, and xrealloc.

Referenced by buildMgmtStatsReply(), dnxBuildNodeStatsReply(), dnxNodeListBuilder(), and getOptions().

static char* buildHelpReply ( void   )  [static]

Build an allocated response buffer for the HELP request.

Returns:
A pointer to an allocated response buffer, or 0 if out of memory.

Definition at line 839 of file dnxClientMain.c.

References xstrdup.

Referenced by dnxAgentServer(), and processCommands().

static char* buildMgmtCfgReply ( void   )  [static]

Build an allocated response buffer for the current configuration.

Returns:
A pointer to an allocated response buffer, or 0 if out of memory.

Definition at line 964 of file dnxClientMain.c.

References dnxCfgParserGetCfg(), xfree, and xmalloc.

Referenced by dnxAgentServer(), and processCommands().

static char* buildMgmtStatsReply ( char *  req  )  [static]

static DnxCfgData* copyCfgData ( DnxCfgData org  )  [static]

Make a dynamic copy of all configuration data.

Parameters:
[in] org - the structure to be copied.
Returns:
Pointer to allocated copy, or 0 on memory allocation failure.

Definition at line 1008 of file dnxClientMain.c.

References DnxCfgData::agentUrl, DnxWlmCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxWlmCfgData::dispatcherUrl, freeCfgData(), DnxCfgData::group, DnxCfgData::logFilePath, DnxCfgData::pluginPath, DnxCfgData::runPath, DnxCfgData::user, DnxCfgData::wlm, xmalloc, and xstrdup.

Referenced by dnxReconfigure(), and processCommands().

static int createPidFile ( char *  base  )  [static]

Create the process id (pid) lock file.

Parameters:
[in] base - the base file name to use for the pid file name.
Returns:
Zero on success, or a non-zero error code.

Definition at line 606 of file dnxClientMain.c.

References dnxLog(), DnxCfgData::runPath, and s_lockfd.

Referenced by main().

static int daemonize ( char *  base  )  [static]

Turn this process into a daemon.

Parameters:
[in] base - the base file name of this program.
Returns:
Zero on success, or a non-zero error value.

Definition at line 672 of file dnxClientMain.c.

References dnxLog(), and DnxCfgData::runPath.

Referenced by main().

static int dropPrivileges ( void   )  [static]

Drop privileges to configured user and group.

Returns:
Zero on success, or a non-zero error value.

Definition at line 721 of file dnxClientMain.c.

References dnxLog(), DnxCfgData::group, and DnxCfgData::user.

Referenced by main().

static void freeCfgData ( DnxCfgData cpy  )  [static]

Release a previously copied configuration data structure.

Parameters:
[in] cpy - the structure to be freed.

Definition at line 985 of file dnxClientMain.c.

References DnxCfgData::agentUrl, DnxWlmCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxWlmCfgData::dispatcherUrl, DnxCfgData::group, DnxCfgData::logFilePath, DnxCfgData::pluginPath, DnxCfgData::runPath, DnxCfgData::user, DnxCfgData::wlm, and xfree.

Referenced by copyCfgData(), dnxReconfigure(), and processCommands().

static int getOptions ( int  argc,
char **  argv 
) [static]

Parse command line options.

Parameters:
[in] argc - the number of elements in the argv array.
[in] argv - a null-terminated array of command-line arguments.
Returns:
Zero on success, or a non-zero error value.

Definition at line 293 of file dnxClientMain.c.

References appendString(), DNX_DEFAULT_NODE_CONFIG_FILE, s_cfgfile, s_cmdover, s_dbgflag, s_progname, usage(), and version().

Referenced by main().

static int initClientComm ( void   )  [static]

Initializes a client communication channels and sub-systems.

Returns:
Zero on success, or a non-zero error code.

Definition at line 538 of file dnxClientMain.c.

References DnxCfgData::agentUrl, DNX_MODE_PASSIVE, DNX_OK, dnxChanMapAdd(), dnxChanMapDelete(), dnxChanMapInit(), dnxChanMapRelease(), dnxConnect(), dnxErrorString(), and dnxLog().

Referenced by main().

static int initConfig ( char *  cfgfile  )  [static]

static void logGblConfigChanges ( DnxCfgData ocp,
DnxCfgData ncp 
) [static]

Log changes between old and new global configuration data sets.

Dynamic reconfiguration of dispatcher and collector URL's is not allowed so we don't need to check differences in those string values.

Parameters:
[in] ocp - a reference to the old configuration data set.
[in] ncp - a reference to the new configuration data set.

Definition at line 792 of file dnxClientMain.c.

References DnxCfgData::agentUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, dnxLog(), DnxCfgData::group, DnxCfgData::logFilePath, DnxCfgData::pluginPath, DnxCfgData::runPath, and DnxCfgData::user.

Referenced by dnxReconfigure(), and processCommands().

int main ( int  argc,
char **  argv 
)

The main program entry point for the dnxClient service.

Parameters:
[in] argc - the number of elements in the argv array.
[in] argv - a null-terminated array of command-line arguments.
Returns:
Zero on success, or a non-zero error code that is returned to the shell. Any non-zero codes should be values between 1 and 127.

Definition at line 1169 of file dnxClientMain.c.

References DnxCfgData::agentUrl, DnxWlmCfgData::collectorUrl, createPidFile(), daemonize(), DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxWlmCfgData::dispatcherUrl, DNX_OK, dnxDebug(), dnxErrorString(), dnxLog(), dnxLogInit(), dnxPluginInit(), dnxPluginRelease(), dnxWlmCreate(), dnxWlmDestroy(), dropPrivileges(), getOptions(), initClientComm(), initConfig(), DnxCfgData::logFilePath, DnxCfgData::pluginPath, processCommands(), releaseClientComm(), releaseConfig(), removePidFile(), s_cfgfile, s_dbgflag, s_progname, sighandler(), VERSION, DnxCfgData::wlm, and xheapchk.

static int processCommands ( void   )  [static]

static void releaseClientComm ( void   )  [static]

Release resources associated with the client communications sub-system.

Definition at line 574 of file dnxClientMain.c.

References dnxChanMapDelete(), dnxChanMapRelease(), and dnxDisconnect().

Referenced by main().

static void releaseConfig ( void   )  [static]

Cleanup the config file parser.

Definition at line 456 of file dnxClientMain.c.

References dnxCfgParserDestroy(), s_cmdover, and xfree.

Referenced by initConfig(), main(), nebmodule_deinit(), and nebmodule_init().

static void removePidFile ( char *  base  )  [static]

Remove an existing process id (pid) lock file.

Parameters:
[in] base - the base file name to use for the pid file name.

Definition at line 649 of file dnxClientMain.c.

References DnxCfgData::runPath, and s_lockfd.

Referenced by main().

static void sighandler ( int  sig  )  [static]

The global signal handler for the dnxClient process.

Parameters:
[in] sig - the signal number received from the system.

Definition at line 587 of file dnxClientMain.c.

References s_debugsig, s_reconfig, and s_shutdown.

Referenced by main().

static void usage ( char *  base  )  [static]

Display program usage text to STDERR and exit with an error.

Parameters:
[in] base - the base file name of this program.

Definition at line 201 of file dnxClientMain.c.

References OL_CFGFILE, OL_DBGFILE, OL_DBGLEVEL, OL_DEBUG, OL_GROUP, OL_HELP, OL_LOGFILE, OL_RUNPATH, OL_USER, OL_VERSION, and version().

Referenced by getOptions(), and main().

static int validateCfg ( DnxCfgDict dict,
void **  vptrs,
void *  passthru 
) [static]

Validate a configuration data structure in context.

Parameters:
[in] dict - the dictionary used by the DnxCfgParser.
[in] vptrs - an array of opaque objects (either pointers or values) to be checked.
[in] passthru - an opaque pointer passed through from dnxCfgParserCreate.
Returns:
Zero on success, or a non-zero error value. This error value is passed back through dnxCfgParserParse.

Definition at line 398 of file dnxClientMain.c.

References DnxCfgData::agentUrl, cfg, DnxWlmCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxWlmCfgData::dispatcherUrl, DNX_ERR_INVALID, dnxLog(), DnxCfgData::group, DnxCfgData::logFilePath, DnxWlmCfgData::maxResults, DnxWlmCfgData::maxRetries, DnxCfgData::pluginPath, DnxWlmCfgData::pollInterval, DnxWlmCfgData::poolGrow, DnxWlmCfgData::poolInitial, DnxWlmCfgData::poolMax, DnxWlmCfgData::poolMin, DnxWlmCfgData::reqTimeout, DnxCfgData::runPath, DnxWlmCfgData::showNodeAddr, DnxWlmCfgData::shutdownGrace, DnxWlmCfgData::ttlBackoff, DnxCfgData::user, and DnxCfgData::wlm.

Referenced by initConfig().

static void version ( FILE *  fp,
char *  base 
) [static]

Display program version information to a specified stream.

Parameters:
[in] fp - the stream to which version info should be printed.
[in] base - the base file name of this program.

Definition at line 184 of file dnxClientMain.c.

References versionText(), and xfree.

Referenced by getOptions(), and usage().

static char* versionText ( char *  base  )  [static]

Format version text to an allocated string buffer.

Caller is responsible to free memory buffer returned.

Parameters:
[in] base - the base file name of this program.
Returns:
An allocated string buffer containing version text.

Definition at line 149 of file dnxClientMain.c.

References DNX_DEFAULT_DBGLOG, DNX_DEFAULT_GROUP, DNX_DEFAULT_LOG, DNX_DEFAULT_NODE_CONFIG_FILE, DNX_DEFAULT_RUN_PATH, DNX_DEFAULT_USER, PACKAGE_BUGREPORT, VERSION, and xstrdup.

Referenced by dnxAgentServer(), processCommands(), version(), and versionText().


Variable Documentation

DnxChannel* s_agent [static]

The agent management channel.

Definition at line 127 of file dnxClientMain.c.

DnxCfgData s_cfg [static]

The system configuration parameters.

Definition at line 124 of file dnxClientMain.c.

char* s_cfgfile [static]

The system configuration file name.

Definition at line 129 of file dnxClientMain.c.

Referenced by getOptions(), initConfig(), and main().

char* s_cmdover = 0 [static]

The command line overrides string.

Definition at line 130 of file dnxClientMain.c.

Referenced by getOptions(), initConfig(), and releaseConfig().

int s_dbgflag = 0 [static]

The system debug flag.

Definition at line 131 of file dnxClientMain.c.

Referenced by getOptions(), main(), and processCommands().

int s_debugsig = 0 [static]

The debug toggle signal flag.

Definition at line 134 of file dnxClientMain.c.

Referenced by processCommands(), and sighandler().

int s_lockfd = -1 [static]

The system PID file descriptor.

Definition at line 135 of file dnxClientMain.c.

Referenced by createPidFile(), and removePidFile().

The system configuration parser.

Definition at line 125 of file dnxClientMain.c.

char* s_progname [static]

The base program name.

Definition at line 128 of file dnxClientMain.c.

Referenced by getOptions(), main(), processCommands(), usage(), and versionText().

int s_reconfig = 0 [static]

The reconfigure signal flag.

Definition at line 133 of file dnxClientMain.c.

Referenced by dnxAgentServer(), dnxAgentSignalReconfig(), processCommands(), and sighandler().

int s_shutdown = 0 [static]

The shutdown signal flag.

Definition at line 132 of file dnxClientMain.c.

Referenced by dnxAgentServer(), dnxInitAgent(), dnxReleaseAgent(), processCommands(), and sighandler().

DnxWlm* s_wlm = 0 [static]

The system worker thread pool.

Definition at line 126 of file dnxClientMain.c.


Generated on Tue Apr 13 15:48:07 2010 for DNX by  doxygen 1.5.6