dnxServerMain.c File Reference

Implements the DNX server child process main entry point. More...

#include "dnxServerMain.h"
#include "dnxNebMain.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxCfgParser.h"
#include "dnxLogging.h"
#include "dnxCollector.h"
#include "dnxDispatcher.h"
#include "dnxRegistrar.h"
#include "dnxJobList.h"
#include "dnxStats.h"
#include "dnxXml.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <signal.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.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 SYSCONFDIR   "/etc"
#define SYSLOGDIR   "/var/log"
#define COMPILE_FLAGS   "<unknown>"
#define elemcount(x)   (sizeof(x)/sizeof(*(x)))
#define DNX_DEFAULT_SERVER_CONFIG_FILE   SYSCONFDIR "/dnxServer.cfg"
#define DNX_DEFAULT_LOG   SYSLOGDIR "/dnxsrv.log"
#define DNX_DEFAULT_DBGLOG   SYSLOGDIR "/dnxsrv.dbg.log"
#define DNX_DEFAULT_SERVER_PATH   SYSBINDIR "/dnxServer"
#define OL_CFGFILE
#define OL_QUEUESIZE
#define OL_VERSION
#define OL_HELP

Functions

static void version (FILE *fp)
 Display program version information to a specified stream.
static void usage (void)
 Display program usage text to STDERR and exit with an error.
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 int initConfig (char *cfgfile)
 Read and parse the dnxServer configuration file.
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 void logGblConfigChanges (DnxCfgData *ocp, DnxCfgData *ncp)
 Log changes between old and new global configuration data sets.
static int dnxCalculateJobListSize (void)
 Calculate the optimal size of the job list.
static int dnxPostNewJob (DnxJobList *joblist, DnxJobTransfer *job, DnxNodeRequest *pNode)
 Post a new job from Nagios to the dnxServer job queue.
static int ProcessJobTransferMsg (DnxJobTransfer *job, DnxNodeRequest *node)
 Transfer a job from the plubin and post it for execution.
static int GetMsgHeader (DnxMsgHeader *phdr)
 Retrieve and validate the next message's header.
static int SendMsgResponse (int result)
 Send ACK/NAK (result code of requested operation) to plugin.
static int processRequests ()
 Process inbound service requests.
static int dnxServerDeInit (void)
 Deinitialize the dnx server.
static int dnxServerInit (void)
 Initialize the dnxServer.
static void sighandler (int sig)
 The global signal handler for the dnxServer process.
char * versionText (void)
 Format version text to an allocated string buffer.
void dnxReconfigure (void)
 Configuration changes have been made; reread the config file.
int dnxPostResult (void *payload, unsigned long serial, time_t start_time, unsigned delta, int early_timeout, int res_code, char *res_data)
 Post a completed service request to the Nagios service result buffer.
void dnxJobCleanup (DnxNewJob *pJob)
 Release all resources associated with a job object.
int dnxAuditJob (DnxNewJob *pJob, char *action)
 Send an audit message to the dnx server audit log.
int main (int argc, char **argv)
 The main program entry point for the dnx server daemon.

Variables

static DnxCfgData cfg
 The server configuration parameters.
static DnxCfgParserparser
 The system configuration parser.
static DnxJobListjoblist
 The master job list.
static DnxRegistrarregistrar
 The client node registrar.
static DnxDispatcherdispatcher
 The job list dispatcher.
static DnxCollectorcollector
 The job list results collector.
static time_t start_time
 The module start time.
static char * s_cfgfile
 The configuration file.
static int s_queuesize
 The Nagios service queue size.
static char * s_progname
 The base program name.
static char * s_cmdover = 0
 The command line overrides string.


Detailed Description

Implements the DNX server child process main entry point.

Listens on an IPC pipe for service check requests sent by the DNX Nagios Plugin module and dispatches them to distributed worker nodes.

Author:
John Calcote (dnx-devel@lists.sourceforge.net)
Attention:
Please submit patches to http://dnx.sourceforge.net

Definition in file dnxServerMain.c.


Define Documentation

#define COMPILE_FLAGS   "<unknown>"

Definition at line 68 of file dnxServerMain.c.

#define DNX_DEFAULT_DBGLOG   SYSLOGDIR "/dnxsrv.dbg.log"

Definition at line 87 of file dnxServerMain.c.

#define DNX_DEFAULT_LOG   SYSLOGDIR "/dnxsrv.log"

Definition at line 86 of file dnxServerMain.c.

#define DNX_DEFAULT_SERVER_CONFIG_FILE   SYSCONFDIR "/dnxServer.cfg"

Definition at line 85 of file dnxServerMain.c.

#define DNX_DEFAULT_SERVER_PATH   SYSBINDIR "/dnxServer"

Definition at line 88 of file dnxServerMain.c.

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

Definition at line 83 of file dnxServerMain.c.

#define OL_CFGFILE

#define OL_HELP

#define OL_QUEUESIZE

Referenced by usage().

#define OL_VERSION

#define SYSCONFDIR   "/etc"

Definition at line 60 of file dnxServerMain.c.

#define SYSLOGDIR   "/var/log"

Definition at line 64 of file dnxServerMain.c.

#define VERSION   "<unknown>"

Definition at line 38 of file dnxServerMain.c.


Function Documentation

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 358 of file dnxServerMain.c.

References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::authWorkerNodes, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxCfgData::dispatcherUrl, DnxCfgData::expirePollInterval, DnxCfgData::logFilePath, DnxCfgData::maxNodeRequests, DnxCfgData::minServiceSlots, xmalloc, and xstrdup.

int dnxAuditJob ( DnxNewJob pJob,
char *  action 
)

Send an audit message to the dnx server audit log.

Parameters:
[in] pJob - the job to be audited.
[in] action - the audit action that we're logging.
Returns:
Zero on success or a non-zero error value.

Todo:
This conversion should take place in the dnxUdpRead function and the resultant address string stored in the DnxNewJob structure. This would have two benefits:
1. Encapsulates conversion at the protocol level. 2. Saves some time during logging.

Definition at line 953 of file dnxServerMain.c.

Referenced by dnxCollector(), dnxDispatcher(), dnxPostNewJob(), and dnxTimer().

static int dnxCalculateJobListSize ( void   )  [static]

Calculate the optimal size of the job list.

Assumes the caller will actually use the returned value to allocate the job list. Based on this assumption, this routine logs messages indicating when various configuration overrides have taken effect.

Returns:
The calculated size of the job list.

Definition at line 460 of file dnxServerMain.c.

References dnxLog(), DnxCfgData::maxNodeRequests, DnxCfgData::minServiceSlots, and s_queuesize.

void dnxJobCleanup ( DnxNewJob pJob  ) 

Release all resources associated with a job object.

Parameters:
[in] pJob - the job to be freed.

Definition at line 942 of file dnxServerMain.c.

Referenced by dnxCollector(), and dnxTimer().

static int dnxPostNewJob ( DnxJobList joblist,
DnxJobTransfer job,
DnxNodeRequest pNode 
) [static]

Post a new job from Nagios to the dnxServer job queue.

Parameters:
[in] joblist - the job list to which the new job should be posted.
[in] job - the job as transferred from the plugin module.
[in] pNode - a dnxServer node request structure that is being posted with this job. The dispatcher thread will send the job to the associated node.
Returns:
Zero on success, or a non-zero error value.

Definition at line 504 of file dnxServerMain.c.

References DnxJobTransfer::cmd, DnxNewJob::cmd, DNX_OBJ_JOB, DNX_OK, dnxAuditJob(), dnxDebug(), dnxJobListAdd(), dnxLog(), dnxMakeXID(), dnxStatsInc(), DnxJobTransfer::expires, DnxNewJob::expires, JOBS_HANDLED, JOBS_REJECTED_NO_SLOTS, DnxXID::objSerial, DnxJobTransfer::payload, DnxNewJob::payload, DnxNewJob::pNode, DnxJobTransfer::serial, DnxJobTransfer::start_time, DnxNewJob::start_time, DnxJobTransfer::timeout, DnxNewJob::timeout, DnxNewJob::xid, and xstrdup.

int dnxPostResult ( void *  payload,
unsigned long  serial,
time_t  start_time,
unsigned  delta,
int  early_timeout,
int  res_code,
char *  res_data 
)

Post a completed service request to the Nagios service result buffer.

If early_timeout is true (1), then res_code will be reset to STATE_UNKNOWN, so you might as well pass zero for res_code.

Parameters:
[in] payload - An opaque pointer to the nagios service structure and other relevant results data.
[in] serial - the job serial number.
[in] start_time - the nagios service object start time.
[in] delta - the running time of the nagios service object in seconds.
[in] early_timeout - boolean; true means the job DID time out.
[in] res_code - the result code of this job.
[in] res_data - the resulting STDOUT output text of this job.
Returns:
Zero on success, or a non-zero error code.

Definition at line 881 of file dnxServerMain.c.

References DnxResultTransfer::delta, DNX_ERR_MEMORY, DNX_MSG_RESULT_TRANSFER, DNX_MSG_SIGNATURE, DNX_PLGFD, dnxDebug(), dnxStatsInc(), DnxResultTransfer::early_timeout, DnxResultTransfer::hdr, DnxMsgHeader::msgtype, DnxResultTransfer::payload, POST_RESULTS_FAILED, POST_RESULTS_OK, DnxResultTransfer::res_code, DnxResultTransfer::res_data, RESULTS_FAILED, RESULTS_OK, RESULTS_TIMED_OUT, DnxResultTransfer::serial, DnxMsgHeader::signature, DnxResultTransfer::start_time, DnxMsgHeader::structsz, xfree, and xmalloc.

void dnxReconfigure ( void   ) 

Configuration changes have been made; reread the config file.

Normally, this routine would be called by the signal handler, but we may do things in here that are not legal in a signal handlers. So instead this routine is called from the agent thread, and the signal handler merely notifies the agent that a reconfigure should be done.

Definition at line 863 of file dnxServerMain.c.

References copyCfgData(), dnxCfgParserParse(), dnxErrorString(), dnxLog(), freeCfgData(), and logGblConfigChanges().

Referenced by dnxAgentServer().

static int dnxServerDeInit ( void   )  [static]

Deinitialize the dnx server.

Returns:
Always returns zero.

Definition at line 737 of file dnxServerMain.c.

References dnxChanMapRelease(), dnxCollectorDestroy(), dnxDispatcherDestroy(), dnxJobListDestroy(), dnxRegistrarDestroy(), dnxReleaseAgent(), and dnxStatsCleanup().

Referenced by ehProcessData(), main(), and nebmodule_deinit().

static int dnxServerInit ( void   )  [static]

static void freeCfgData ( DnxCfgData cpy  )  [static]

Release a previously copied configuration data structure.

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

Definition at line 337 of file dnxServerMain.c.

References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::authWorkerNodes, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::dispatcherUrl, DnxCfgData::logFilePath, and xfree.

static int GetMsgHeader ( DnxMsgHeader phdr  )  [static]

Retrieve and validate the next message's header.

Parameters:
[in] phdr - the header buffer to be filled.
Returns:
zero on success or a non-zero error code.

Definition at line 590 of file dnxServerMain.c.

References DNX_ERR_UNSUPPORTED, DNX_MAX_XFER_SIZE, DNX_MSG_SIGNATURE, DNX_SRVFD, dnxDebug(), DnxMsgHeader::signature, and DnxMsgHeader::structsz.

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 180 of file dnxServerMain.c.

References DNX_DEFAULT_SERVER_CONFIG_FILE, s_cfgfile, s_progname, s_queuesize, usage(), and version().

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 395 of file dnxServerMain.c.

References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::authWorkerNodes, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxCfgData::dispatcherUrl, dnxLog(), DnxCfgData::expirePollInterval, DnxCfgData::logFilePath, DnxCfgData::maxNodeRequests, and DnxCfgData::minServiceSlots.

int main ( int  argc,
char **  argv 
)

The main program entry point for the dnx server daemon.

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 991 of file dnxServerMain.c.

References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxCfgData::dispatcherUrl, DNX_OK, dnxCfgParserDestroy(), dnxDebug(), dnxErrorString(), dnxLog(), dnxLogInit(), dnxServerDeInit(), dnxServerInit(), getOptions(), initConfig(), DnxCfgData::logFilePath, processRequests(), s_cfgfile, sighandler(), start_time, VERSION, and xheapchk.

static int ProcessJobTransferMsg ( DnxJobTransfer job,
DnxNodeRequest node 
) [static]

Transfer a job from the plubin and post it for execution.

Parameters:
[in,out] job - the address of the current job structure pointer.
[in] node - the client node request to associate with this job. This value may be null, in which case this routine should allocate it.
Returns:
zero on success or a non-zero error code.

Definition at line 546 of file dnxServerMain.c.

References DNX_SRVFD, dnxDebug(), dnxErrorString(), dnxGetNodeRequest(), dnxPostNewJob(), DnxJobTransfer::hdr, and DnxMsgHeader::structsz.

Referenced by processRequests().

static int processRequests (  )  [static]

Process inbound service requests.

If there's a worker node request available, hang on a read request waiting to assign that node to an inbound service request. Otherwise don't wait for a request node to become available.

Returns:
this thread always returns zero.

Definition at line 672 of file dnxServerMain.c.

References DNX_MSG_JOB_TRANSFER, DNX_MSG_RESERVE_NODEREQ, DNX_MSG_TERMINATE, DNX_SAKFD, DNX_SRVFD, dnxDebug(), dnxGetNodeRequest(), dnxLog(), GetMsgHeader(), DnxJobTransfer::hdr, DnxMsgHeader::msgtype, ProcessJobTransferMsg(), SendMsgResponse(), DnxMsgHeader::structsz, xfree, and xrealloc.

Referenced by main().

static int SendMsgResponse ( int  result  )  [static]

Send ACK/NAK (result code of requested operation) to plugin.

Parameters:
[in] result - the result code to be sent.
Returns:
zero on success or a non-zero error code.

Definition at line 634 of file dnxServerMain.c.

References DNX_SAKFD, and dnxDebug().

Referenced by processRequests().

static void sighandler ( int  sig  )  [static]

The global signal handler for the dnxServer process.

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

Definition at line 823 of file dnxServerMain.c.

References dnxAgentSignalReconfig().

static void usage ( void   )  [static]

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

Definition at line 142 of file dnxServerMain.c.

References OL_CFGFILE, OL_HELP, OL_QUEUESIZE, OL_VERSION, s_progname, and version().

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. In this routine, it's the regex_t object into which we should parse the regular expression if one is given.
Returns:
Zero on success, or a non-zero error value. This error value is passed back through dnxCfgParserParse.

Definition at line 243 of file dnxServerMain.c.

References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::authWorkerNodes, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxCfgData::dispatcherUrl, DNX_ERR_INVALID, dnxLog(), DnxCfgData::expirePollInterval, DnxCfgData::logFilePath, DnxCfgData::maxNodeRequests, and DnxCfgData::minServiceSlots.

static void version ( FILE *  fp  )  [static]

Display program version information to a specified stream.

Parameters:
[in] fp - the stream to which version info should be printed.

Definition at line 127 of file dnxServerMain.c.

References versionText(), and xfree.

char* versionText ( void   ) 

Format version text to an allocated string buffer.

Caller is responsible to free memory buffer returned, using xfree.

Returns:
An allocated string buffer containing version text.

Definition at line 836 of file dnxServerMain.c.


Variable Documentation

DnxCfgData cfg [static]

The server configuration parameters.

Definition at line 107 of file dnxServerMain.c.

The job list results collector.

Definition at line 112 of file dnxServerMain.c.

The job list dispatcher.

Definition at line 111 of file dnxServerMain.c.

DnxJobList* joblist [static]

The master job list.

Definition at line 109 of file dnxServerMain.c.

DnxCfgParser* parser [static]

The system configuration parser.

Definition at line 108 of file dnxServerMain.c.

The client node registrar.

Definition at line 110 of file dnxServerMain.c.

char* s_cfgfile [static]

The configuration file.

Definition at line 114 of file dnxServerMain.c.

char* s_cmdover = 0 [static]

The command line overrides string.

Definition at line 117 of file dnxServerMain.c.

char* s_progname [static]

The base program name.

Definition at line 116 of file dnxServerMain.c.

int s_queuesize [static]

The Nagios service queue size.

Definition at line 115 of file dnxServerMain.c.

Referenced by dnxCalculateJobListSize(), and getOptions().

time_t start_time [static]

The module start time.

Definition at line 113 of file dnxServerMain.c.


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