-rw-r--r-- | src/dudki.cc | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/dudki.cc b/src/dudki.cc index c966695..3af5372 100644 --- a/src/dudki.cc +++ b/src/dudki.cc | |||
@@ -213,54 +213,53 @@ int main(int argc,char **argv) { | |||
213 | break; | 213 | break; |
214 | case op_signal: | 214 | case op_signal: |
215 | try { | 215 | try { |
216 | if(optind>=argc) { | 216 | if(optind>=argc) { |
217 | signal_self(config,op_signum); | 217 | signal_self(config,op_signum); |
218 | }else{ | 218 | }else{ |
219 | int failures = 0; | 219 | int failures = 0; |
220 | for(int narg=optind;narg<argc;narg++) { | 220 | for(int narg=optind;narg<argc;narg++) { |
221 | try { | 221 | try { |
222 | processes_t::const_iterator i = config.processes.find(argv[narg]); | 222 | processes_t::const_iterator i = config.processes.find(argv[narg]); |
223 | if(i==config.processes.end()) | 223 | if(i==config.processes.end()) |
224 | throw runtime_error("no such process configured"); | 224 | throw runtime_error("no such process configured"); |
225 | if(op_signum) | 225 | if(op_signum) |
226 | i->second.signal(op_signum); | 226 | i->second.signal(op_signum); |
227 | else | 227 | else |
228 | i->second.check(); | 228 | i->second.check(); |
229 | }catch(exception& e) { | 229 | }catch(exception& e) { |
230 | cerr << "dudki(" << argv[narg] << "): " << e.what() << endl; | 230 | cerr << "dudki(" << argv[narg] << "): " << e.what() << endl; |
231 | failures++; | 231 | failures++; |
232 | } | 232 | } |
233 | } | 233 | } |
234 | if(failures) | 234 | if(failures) |
235 | throw runtime_error("not all processes have been successfully signaled"); | 235 | throw runtime_error("not all processes have been successfully signaled"); |
236 | } | 236 | } |
237 | if(!op_signum) | 237 | exit(0); |
238 | exit(0); | ||
239 | }catch(exception& e) { | 238 | }catch(exception& e) { |
240 | if(!op_signum) | 239 | exit(1); |
241 | exit(1); | ||
242 | } | 240 | } |
241 | break; | ||
243 | case op_ensure: | 242 | case op_ensure: |
244 | try { | 243 | try { |
245 | signal_self(config,0); | 244 | signal_self(config,0); |
246 | break; | 245 | break; |
247 | }catch(exception& e) { | 246 | }catch(exception& e) { |
248 | syslog(LOG_NOTICE,"The dudki process is down, taking its place"); | 247 | syslog(LOG_NOTICE,"The dudki process is down, taking its place"); |
249 | config.daemonize = true; | 248 | config.daemonize = true; |
250 | }catch(int zero) { | 249 | }catch(int zero) { |
251 | // we throw zero in case we're ensuring that this very process is running. | 250 | // we throw zero in case we're ensuring that this very process is running. |
252 | // we don't have to daemonize if we're daemonic. | 251 | // we don't have to daemonize if we're daemonic. |
253 | config.daemonize = false; | 252 | config.daemonize = false; |
254 | } | 253 | } |
255 | case op_default: | 254 | case op_default: |
256 | case op_work: | 255 | case op_work: |
257 | { | 256 | { |
258 | if(config.daemonize) { | 257 | if(config.daemonize) { |
259 | pid_t pf = fork(); | 258 | pid_t pf = fork(); |
260 | if(pf<0) | 259 | if(pf<0) |
261 | throw runtime_error(string(__PRETTY_FUNCTION__)+": failed to fork()"); | 260 | throw runtime_error(string(__PRETTY_FUNCTION__)+": failed to fork()"); |
262 | if(pf) { | 261 | if(pf) { |
263 | _exit(0); | 262 | _exit(0); |
264 | } | 263 | } |
265 | } | 264 | } |
266 | pid_file pidfile; | 265 | pid_file pidfile; |
@@ -268,25 +267,26 @@ int main(int argc,char **argv) { | |||
268 | signal(SIGINT,lethal_signal_handler); | 267 | signal(SIGINT,lethal_signal_handler); |
269 | signal(SIGABRT,lethal_signal_handler); | 268 | signal(SIGABRT,lethal_signal_handler); |
270 | signal(SIGTERM,lethal_signal_handler); | 269 | signal(SIGTERM,lethal_signal_handler); |
271 | signal(SIGHUP,sighup_handler); | 270 | signal(SIGHUP,sighup_handler); |
272 | sigset_t sset; | 271 | sigset_t sset; |
273 | sigemptyset(&sset); | 272 | sigemptyset(&sset); |
274 | sigaddset(&sset,SIGINT); sigaddset(&sset,SIGABRT); | 273 | sigaddset(&sset,SIGINT); sigaddset(&sset,SIGABRT); |
275 | sigaddset(&sset,SIGTERM); sigaddset(&sset,SIGHUP); | 274 | sigaddset(&sset,SIGTERM); sigaddset(&sset,SIGHUP); |
276 | sigprocmask(SIG_UNBLOCK,&sset,NULL); | 275 | sigprocmask(SIG_UNBLOCK,&sset,NULL); |
277 | while(!finishing) { | 276 | while(!finishing) { |
278 | check_herd(config); | 277 | check_herd(config); |
279 | sleep(config.check_interval); | 278 | sleep(config.check_interval); |
280 | } | 279 | } |
281 | if(restarting) | 280 | if(restarting) |
282 | execvp(_argv[0],_argv); | 281 | execvp(_argv[0],_argv); |
283 | } | 282 | } |
284 | break; | 283 | break; |
285 | default: | 284 | default: |
286 | throw runtime_error(string(__PRETTY_FUNCTION__)+": internal error"); | 285 | throw runtime_error(string(__PRETTY_FUNCTION__)+": internal error"); |
287 | } | 286 | } |
288 | }catch(exception& e) { | 287 | }catch(exception& e) { |
289 | cerr << "Oops: " << e.what() << endl; | 288 | cerr << "Oops: " << e.what() << endl; |
290 | return 1; | 289 | return 1; |
291 | } | 290 | } |
291 | exit(0); | ||
292 | } | 292 | } |