-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/dudki.cc | 5 |
3 files changed, 8 insertions, 2 deletions
@@ -1,2 +1,5 @@ +0.1 + - initgroups() before executing RestartCommand. + - more civilized restart. 0.0 - Initial release. diff --git a/configure.ac b/configure.ac index 8a2a10b..8521a34 100644 --- a/configure.ac +++ b/configure.ac @@ -1,25 +1,25 @@ -AC_INIT([dudki], [0.0], [dudki-bugs@klever.net]) +AC_INIT([dudki], [0.1], [dudki-bugs@klever.net]) AC_CONFIG_SRCDIR([src/dudki.cc]) AC_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE([dist-bzip2]) AC_PROG_CXX AC_PROG_CC AC_HEADER_SYS_WAIT AC_CHECK_HEADERS([syslog.h unistd.h getopt.h]) AC_HEADER_STDBOOL AC_C_CONST AC_TYPE_UID_T AC_TYPE_PID_T AC_FUNC_FORK AC_HEADER_STDC AC_TYPE_SIGNAL AC_CHECK_FUNCS([dup2 strtol]) AC_CHECK_FUNC([getopt_long],[ AC_DEFINE([HAVE_GETOPT_LONG],[1],[Define to make use of getopt_long]) AC_SUBST(HAVE_GETOPT_LONG,1) ],[ AC_SUBST(HAVE_GETOPT_LONG,0) diff --git a/src/dudki.cc b/src/dudki.cc index b769109..b4e95a7 100644 --- a/src/dudki.cc +++ b/src/dudki.cc @@ -1,56 +1,57 @@ #include <unistd.h> #include <signal.h> #include <syslog.h> #include <iostream> #include <fstream> #include <stdexcept> using namespace std; #include "configuration.h" #include "util.h" #include "config.h" #ifdef HAVE_GETOPT_H # include <getopt.h> #endif #ifndef DEFAULT_CONF_FILE # define DEFAULT_CONF_FILE "/etc/dudki.conf" #endif #define PHEADER PACKAGE " Version " VERSION #define PCOPY "Copyright (c) 2004 Klever Group" bool finishing = false; +bool restarting = false; static char **_argv = NULL; static void lethal_signal_handler(int signum) { syslog(LOG_NOTICE,"Lethal signal received. Terminating."); finishing = true; } static void sighup_handler(int signum) { syslog(LOG_NOTICE,"SUGHUP received, reloading."); - execvp(_argv[0],_argv); + restarting = finishing = true; } void check_herd(configuration& config) { for(processes_t::iterator i=config.processes.begin();i!=config.processes.end();++i) i->second.check(i->first,config); } void signal_self(const configuration& config,int signum) { ifstream pids(config.pidfile.c_str(),ios::in); if(!pids) throw runtime_error("Can't detect running instance"); pid_t pid = 0; pids >> pid; if(!pid) throw runtime_error("Can't detect running instance"); if(pid==getpid()) throw 0; if(kill(pid,signum)) throw runtime_error("Failed to signal running instance"); } int main(int argc,char **argv) { try { _argv = new char*[argc+1]; @@ -216,34 +217,36 @@ int main(int argc,char **argv) { { if(config.daemonize) { pid_t pf = fork(); if(pf<0) throw runtime_error(string(__PRETTY_FUNCTION__)+": failed to fork()"); if(pf) { _exit(0); } } pid_file pidfile; pidfile.set(config.pidfile); signal(SIGINT,lethal_signal_handler); signal(SIGABRT,lethal_signal_handler); signal(SIGTERM,lethal_signal_handler); signal(SIGHUP,sighup_handler); sigset_t sset; sigemptyset(&sset); sigaddset(&sset,SIGINT); sigaddset(&sset,SIGABRT); sigaddset(&sset,SIGTERM); sigaddset(&sset,SIGHUP); sigprocmask(SIG_UNBLOCK,&sset,NULL); while(!finishing) { check_herd(config); sleep(config.check_interval); } + if(restarting) + execvp(_argv[0],_argv); } break; default: throw runtime_error(string(__PRETTY_FUNCTION__)+": internal error"); } }catch(exception& e) { cerr << "Oops: " << e.what() << endl; return 1; } } |