-rw-r--r-- | src/dudki.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/dudki.cc b/src/dudki.cc index 3af5372..91a3342 100644 --- a/src/dudki.cc +++ b/src/dudki.cc | |||
@@ -1,86 +1,86 @@ | |||
1 | #include <unistd.h> | 1 | #include <unistd.h> |
2 | #include <signal.h> | 2 | #include <signal.h> |
3 | #include <syslog.h> | 3 | #include <syslog.h> |
4 | #include <errno.h> | 4 | #include <errno.h> |
5 | #include <iostream> | 5 | #include <iostream> |
6 | #include <fstream> | 6 | #include <fstream> |
7 | #include <stdexcept> | 7 | #include <stdexcept> |
8 | using namespace std; | 8 | using namespace std; |
9 | #include "configuration.h" | 9 | #include "configuration.h" |
10 | #include "util.h" | 10 | #include "util.h" |
11 | 11 | ||
12 | #include "config.h" | 12 | #include "config.h" |
13 | #ifdef HAVE_GETOPT_H | 13 | #ifdef HAVE_GETOPT_H |
14 | # include <getopt.h> | 14 | # include <getopt.h> |
15 | #endif | 15 | #endif |
16 | 16 | ||
17 | #ifndef DEFAULT_CONF_FILE | 17 | #ifndef DEFAULT_CONF_FILE |
18 | # define DEFAULT_CONF_FILE "/etc/dudki.conf" | 18 | # define DEFAULT_CONF_FILE "/etc/dudki.conf" |
19 | #endif | 19 | #endif |
20 | 20 | ||
21 | #define PHEADER PACKAGE " Version " VERSION | 21 | #define PHEADER PACKAGE " Version " VERSION |
22 | #define PCOPY "Copyright (c) 2004 Klever Group" | 22 | #define PCOPY "Copyright (c) 2004-2006 Klever Group" |
23 | 23 | ||
24 | bool finishing = false; | 24 | bool finishing = false; |
25 | bool restarting = false; | 25 | bool restarting = false; |
26 | static char **_argv = NULL; | 26 | static char **_argv = NULL; |
27 | 27 | ||
28 | static void lethal_signal_handler(int signum) { | 28 | static void lethal_signal_handler(int signum) { |
29 | syslog(LOG_NOTICE,"Lethal signal received. Terminating."); | 29 | syslog(LOG_NOTICE,"Lethal signal received. Terminating."); |
30 | finishing = true; | 30 | finishing = true; |
31 | } | 31 | } |
32 | static void sighup_handler(int signum) { | 32 | static void sighup_handler(int signum) { |
33 | syslog(LOG_NOTICE,"SUGHUP received, reloading."); | 33 | syslog(LOG_NOTICE,"SUGHUP received, reloading."); |
34 | restarting = finishing = true; | 34 | restarting = finishing = true; |
35 | } | 35 | } |
36 | 36 | ||
37 | void check_herd(configuration& config) { | 37 | void check_herd(configuration& config) { |
38 | process::prepare_herd(); | 38 | process::prepare_herd(); |
39 | for(processes_t::iterator i=config.processes.begin();i!=config.processes.end();++i) | 39 | for(processes_t::iterator i=config.processes.begin();i!=config.processes.end();++i) |
40 | i->second.check(i->first,config); | 40 | i->second.check(i->first,config); |
41 | process::unprepare_herd(); | 41 | process::unprepare_herd(); |
42 | } | 42 | } |
43 | 43 | ||
44 | void signal_self(const configuration& config,int signum) { | 44 | void signal_self(const configuration& config,int signum) { |
45 | ifstream pids(config.pidfile.c_str(),ios::in); | 45 | ifstream pids(config.pidfile.c_str(),ios::in); |
46 | if(!pids) | 46 | if(!pids) |
47 | throw runtime_error("Can't detect running instance"); | 47 | throw runtime_error("Can't detect running instance"); |
48 | pid_t pid = 0; | 48 | pid_t pid = 0; |
49 | pids >> pid; | 49 | pids >> pid; |
50 | if(!pid) | 50 | if(!pid) |
51 | throw runtime_error("Can't detect running instance"); | 51 | throw runtime_error("Can't detect running instance"); |
52 | if(pid==getpid()) | 52 | if(pid==getpid()) |
53 | throw 0; | 53 | throw 0; |
54 | if(kill(pid,signum)) | 54 | if(kill(pid,signum)) |
55 | throw runtime_error("Failed to signal running instance"); | 55 | throw runtime_error("Failed to signal running instance"); |
56 | } | 56 | } |
57 | 57 | ||
58 | int main(int argc,char **argv) { | 58 | int main(int argc,char **argv) { |
59 | try { | 59 | try { |
60 | _argv = new char*[argc+1]; | 60 | _argv = new char*[argc+1]; |
61 | if(!_argv) | 61 | if(!_argv) |
62 | throw runtime_error("memory allocation problem at the very start"); | 62 | throw runtime_error("memory allocation problem at the very start"); |
63 | memmove(_argv,argv,sizeof(*_argv)*(argc+1)); | 63 | memmove(_argv,argv,sizeof(*_argv)*(argc+1)); |
64 | string config_file = DEFAULT_CONF_FILE; | 64 | string config_file = DEFAULT_CONF_FILE; |
65 | enum { | 65 | enum { |
66 | op_default, | 66 | op_default, |
67 | op_work, | 67 | op_work, |
68 | op_signal, | 68 | op_signal, |
69 | op_ensure, | 69 | op_ensure, |
70 | op_test | 70 | op_test |
71 | } op = op_default; | 71 | } op = op_default; |
72 | int op_signum = 0; | 72 | int op_signum = 0; |
73 | while(true) { | 73 | while(true) { |
74 | #defineSHORTOPTSTRING "f:hVLrkcets:" | 74 | #defineSHORTOPTSTRING "f:hVLrkcets:" |
75 | #ifdef HAVE_GETOPT_LONG | 75 | #ifdef HAVE_GETOPT_LONG |
76 | static struct option opts[] = { | 76 | static struct option opts[] = { |
77 | { "help", no_argument, 0, 'h' }, | 77 | { "help", no_argument, 0, 'h' }, |
78 | { "usage", no_argument, 0, 'h' }, | 78 | { "usage", no_argument, 0, 'h' }, |
79 | { "version", no_argument, 0, 'V' }, | 79 | { "version", no_argument, 0, 'V' }, |
80 | { "license", no_argument, 0, 'L' }, | 80 | { "license", no_argument, 0, 'L' }, |
81 | { "config", required_argument, 0, 'f' }, | 81 | { "config", required_argument, 0, 'f' }, |
82 | { "kill", no_argument, 0, 'k' }, | 82 | { "kill", no_argument, 0, 'k' }, |
83 | { "reload", no_argument, 0, 'r' }, | 83 | { "reload", no_argument, 0, 'r' }, |
84 | { "signal", required_argument, 0, 's' }, | 84 | { "signal", required_argument, 0, 's' }, |
85 | { "check", no_argument, 0, 'c' }, | 85 | { "check", no_argument, 0, 'c' }, |
86 | { "ensure", no_argument, 0, 'e' }, | 86 | { "ensure", no_argument, 0, 'e' }, |