[Onhm-cvs-commits] CVS: Software/onhmagentd/src main.c,1.1,1.2
Status: Planning
Brought to you by:
cheezel
|
From: Brian C. <bch...@us...> - 2005-12-06 12:19:06
|
Update of /cvsroot/onhm/Software/onhmagentd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3160/onhmagentd/src Modified Files: main.c Log Message: Miscellaneous updates to the codebase. Index: main.c =================================================================== RCS file: /cvsroot/onhm/Software/onhmagentd/src/main.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** main.c 20 Aug 2005 06:53:54 -0000 1.1 --- main.c 6 Dec 2005 12:18:53 -0000 1.2 *************** *** 1,14 **** ! #include "daemon.h" ! #include "logger.h" ! ! #define _GNU_SOURCE ! #include <string.h> ! ! int main(void) ! { ! goDaemon(strdup("onhm"), strdup("onhm")); ! initialiseLogging(ONHM_LOG_FILE,strdup("onhmagnt"), strdup("/opt/onhm/logs/agent.log")); ! ! shutdownLogging(); ! return 0; ! } --- 1,102 ---- ! /****************************************************************************** ! * File name: onhmagentd/src/main.c ! * Purpose: To provide the main code for the monitoring agent of the ONHM ! * system. ! * Author: Brian A Cheeseman. ! * Date: 3 December 2005. ! * Copyright: (c) 2004-2005, Brian A Cheeseman. ! * License: GNU General Public License Version 2. See LICENSE for details. ! ******************************************************************************/ ! ! #include "daemon.h" ! #include "logger.h" ! #include "configuration.h" ! #include "agentconfig.h" ! #include <stdio.h> ! #include <unistd.h> ! #include <sys/types.h> ! #include <signal.h> ! ! #define _GNU_SOURCE ! #include <string.h> ! ! void loadConfigData(char *fileName) ! { ! loadConfiguration(fileName, cfg); ! } ! ! void handleSignal(int signal) ! { ! // Process the caught signal. ! switch (signal) ! { ! case SIGHUP: ! logMessage(ONHM_INFO, "Received SIGHUP, Initiating Configuration Reload"); ! break; ! case SIGTERM: ! logMessage(ONHM_INFO, "Received SIGTERM, Initiating Shutdown."); ! continueDaemon = 0; ! break; ! default: ! break; ! } // End of switch(signal) ! } ! ! void installSigHandlers() ! { ! struct sigaction hupAction; ! struct sigaction termAction; ! ! // Setup the sigaction structure to handle the HUP (Hang-Up) signal. ! hupAction.sa_handler = handleSignal; ! hupAction.sa_flags = SA_SIGINFO; ! ! // Install the handler for the HUP (Hang-Up) signal. ! sigaction(SIGHUP, &hupAction, (struct sigaction *)NULL); ! ! // Setup the sigaction structure to handle the TERM (Terminate) signal. ! termAction.sa_handler = handleSignal; ! termAction.sa_flags = SA_SIGINFO; ! ! // Install the handler for the TERM (Terminate) signal. ! sigaction(SIGTERM, &termAction, (struct sigaction *)NULL); ! } ! ! void startDaemonLoop(void) ! { ! continueDaemon = 1; ! while (continueDaemon == 1) ! { ! // Here we will do our work. ! ! // Take a moment for the OS to catch up. ! usleep(10000); ! } ! } ! ! int main(int argc, char **argv) ! { ! // Load our configuration. ! loadConfigData("/opt/onhm/config/agentd.conf"); ! ! // Daemonise our process. ! if (goDaemon(strdup(DaemonUser), strdup(DaemonGroup)) > 0) ! { ! return 0; ! } ! ! // Initialise the logging system. ! initialiseLogging(ONHM_LOG_FILE,strdup("onhmagnt"), strdup("/opt/onhm/logs/agent.log")); ! ! // Install the signal Handlers. ! installSigHandlers(); ! ! // Execute our daemon loop. ! startDaemonLoop(); ! ! // Close the logging system down. ! shutdownLogging(); ! ! // Return to the operating system. ! return 0; ! } |