#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 DnxCfgData * | copyCfgData (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 DnxCfgParser * | s_parser |
The system configuration parser. | |
static DnxWlm * | s_wlm = 0 |
The system worker thread pool. | |
static DnxChannel * | s_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. |
Definition in file dnxClientMain.c.
#define COMPILE_FLAGS "<unknown>" |
Definition at line 95 of file dnxClientMain.c.
#define DNX_DEFAULT_DBGLOG SYSLOGDIR "/dnxcld.debug.log" |
#define DNX_DEFAULT_GROUP DNXGROUP |
#define DNX_DEFAULT_LOG SYSLOGDIR "/dnxcld.log" |
#define DNX_DEFAULT_NODE_CONFIG_FILE SYSCONFDIR "/dnxClient.cfg" |
#define DNX_DEFAULT_PLUGIN_PATH LIBEXECDIR |
#define DNX_DEFAULT_RUN_PATH SYSRUNPATH |
#define DNX_DEFAULT_USER DNXUSER |
#define DNXGROUP "nagios" |
Definition at line 91 of file dnxClientMain.c.
#define DNXUSER "nagios" |
Definition at line 87 of file dnxClientMain.c.
#define elemcount | ( | x | ) | (sizeof(x)/sizeof(*(x))) |
Definition at line 107 of file dnxClientMain.c.
Referenced by buildMgmtStatsReply(), dnxBuildNodeStatsReply(), dnxChanMapInit(), dnxChanMapRelease(), dnxChanMapUrlParse(), dnxErrorString(), dnxParseCfgVar(), dnxPluginExternal(), dnxStatsCleanup(), dnxStatsForEachNode(), execServerProcess(), initWorkerComm(), and pfopen().
#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>" |
#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().
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.
[in] | spp | - the address of a dynamically allocated buffer pointer. |
[in] | fmt | - a printf-like format specifier string. |
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.
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.
Definition at line 964 of file dnxClientMain.c.
References dnxCfgParserGetCfg(), xfree, and xmalloc.
Referenced by dnxAgentServer(), and processCommands().
static char* buildMgmtStatsReply | ( | char * | req | ) | [static] |
Build an allocated response buffer for requested stats values.
[in] | req | - The requested stats in comma-separated string format. |
Definition at line 881 of file dnxClientMain.c.
References DnxWlmStats::active_threads, appendString(), DnxWlmStats::avg_active_threads, DnxWlmStats::avg_exec_time, DnxWlmStats::avg_total_threads, dnxWlmGetStats(), elemcount, DnxWlmStats::job_time, DnxWlmStats::jobs_failed, DnxWlmStats::jobs_received, DnxWlmStats::jobs_succeeded, DnxWlmStats::max_exec_time, DnxWlmStats::min_exec_time, DnxWlmStats::requests_sent, DnxWlmStats::thread_time, DnxWlmStats::threads_created, DnxWlmStats::threads_destroyed, DnxWlmStats::total_threads, and xfree.
Referenced by dnxAgentServer(), and processCommands().
static DnxCfgData* copyCfgData | ( | DnxCfgData * | org | ) | [static] |
Make a dynamic copy of all configuration data.
[in] | org | - the structure to be copied. |
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.
[in] | base | - the base file name to use for the pid file name. |
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.
[in] | base | - the base file name of this program. |
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.
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.
[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.
[in] | argc | - the number of elements in the argv array. |
[in] | argv | - a null-terminated array of command-line arguments. |
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.
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] |
Read and parse the dnxClient configuration file.
[in] | cfgfile | - the configuration file to use. |
Definition at line 470 of file dnxClientMain.c.
References DnxCfgData::agentUrl, DnxWlmCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxWlmCfgData::dispatcherUrl, DNX_CFG_BOOL, DNX_CFG_FSPATH, DNX_CFG_STRING, DNX_CFG_UNSIGNED, DNX_CFG_URL, DNX_DEFAULT_DBGLOG, DNX_DEFAULT_GROUP, DNX_DEFAULT_LOG, DNX_DEFAULT_PLUGIN_PATH, DNX_DEFAULT_RUN_PATH, DNX_DEFAULT_USER, dnxCfgParserCreate(), dnxCfgParserParse(), DnxCfgData::group, DnxCfgData::logFilePath, DnxWlmCfgData::maxResults, DnxWlmCfgData::maxRetries, DnxCfgData::pluginPath, DnxWlmCfgData::pollInterval, DnxWlmCfgData::poolGrow, DnxWlmCfgData::poolInitial, DnxWlmCfgData::poolMax, DnxWlmCfgData::poolMin, releaseConfig(), DnxWlmCfgData::reqTimeout, DnxCfgData::runPath, s_cfgfile, s_cmdover, DnxWlmCfgData::showNodeAddr, DnxWlmCfgData::shutdownGrace, DnxWlmCfgData::ttlBackoff, DnxCfgData::user, validateCfg(), and DnxCfgData::wlm.
Referenced by main(), and nebmodule_init().
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.
[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.
[in] | argc | - the number of elements in the argv array. |
[in] | argv | - a null-terminated array of command-line arguments. |
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] |
The main event loop for the dnxClient process.
Definition at line 1046 of file dnxClientMain.c.
References DnxMgmtRequest::action, DnxMgmtRequest::address, buildHelpReply(), buildMgmtCfgReply(), buildMgmtStatsReply(), copyCfgData(), DNX_ERR_TIMEOUT, DNX_MAX_ADDRESS, DNX_MAX_ADDRSTR, DNX_OK, DNX_REQ_ACK, DNX_REQ_NAK, dnxCfgParserParse(), dnxDebug(), dnxErrorString(), dnxLog(), dnxNtop(), dnxSendMgmtReply(), dnxWaitForMgmtRequest(), dnxWlmResetStats(), freeCfgData(), logGblConfigChanges(), DnxMgmtReply::reply, s_dbgflag, s_debugsig, s_progname, s_reconfig, s_shutdown, DnxMgmtReply::status, versionText(), xfree, DnxMgmtRequest::xid, DnxMgmtReply::xid, and xstrdup.
Referenced by main().
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.
[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.
[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.
[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.
[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. |
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.
[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.
[in] | base | - the base file name of this program. |
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().
DnxChannel* s_agent [static] |
DnxCfgData s_cfg [static] |
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().
DnxCfgParser* s_parser [static] |
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().