author | Michael Krelin <hacker@klever.net> | 2004-07-10 19:59:06 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2004-07-10 19:59:06 (UTC) |
commit | 4f8a6f291a231410a03c438bc9d63a7beb861e7b (patch) (side-by-side diff) | |
tree | 790352f42d045e23e9bbb6ae3a210d4faeae8244 | |
parent | 9148dac885c0325636c2d33715ba248371706d0d (diff) | |
download | dudki-4f8a6f291a231410a03c438bc9d63a7beb861e7b.zip dudki-4f8a6f291a231410a03c438bc9d63a7beb861e7b.tar.gz dudki-4f8a6f291a231410a03c438bc9d63a7beb861e7b.tar.bz2 |
fixed signal handling, so that dudki can be HUP-ped more than once.0.0
-rw-r--r-- | src/dudki.cc | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/dudki.cc b/src/dudki.cc index 3c50e56..b769109 100644 --- a/src/dudki.cc +++ b/src/dudki.cc @@ -167,78 +167,83 @@ int main(int argc,char **argv) { exit(1); } op = op_test; break; default: cerr << "Huh??" << endl; exit(1); break; } } const char *sid = *argv; const char *t; while(t = index(sid,'/')) { sid = t; sid++; } openlog(sid,LOG_CONS|LOG_PERROR|LOG_PID,LOG_DAEMON); configuration config; config.parse(config_file); switch(op) { case op_test: cerr << "Configuration OK" << endl; break; case op_hup: signal_self(config,SIGHUP); break; case op_term: signal_self(config,SIGTERM); break; case op_check: try{ signal_self(config,0); exit(0); }catch(exception& e) { exit(1); } case op_ensure: try { signal_self(config,0); break; }catch(exception& e) { syslog(LOG_NOTICE,"The dudki process is down, taking its place"); config.daemonize = true; }catch(int zero) { // we throw zero in case we're ensuring that this very process is running. // we don't have to daemonize if we're daemonic. config.daemonize = false; } case op_default: case op_work: { 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); } } break; default: throw runtime_error(string(__PRETTY_FUNCTION__)+": internal error"); } }catch(exception& e) { cerr << "Oops: " << e.what() << endl; return 1; } } |