From db9ffc6dafce568e0b70d064411db81933d61eb4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 17 Jul 2009 15:58:51 +0200 Subject: On exit, take care to emit consistent exit status. If we were Ctrl-C'ed, then we should exit by killing ourself, not exit(N). Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index c28331fc..dff8de6c 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -42,13 +42,14 @@ void print_help() int main(int argc, char** argv) { int daemonize = 1; - /*signal handlers */ + + /* signal handlers */ signal(SIGTERM, handle_fatal_signal); signal(SIGINT, handle_fatal_signal); + try { - - if (argc > 1) + if (argv[1]) { if (strcmp(argv[1], "-d") == 0) { @@ -97,7 +98,14 @@ int main(int argc, char** argv) { std::cerr << "Cannot create daemon: " << e.what() << std::endl; } + delete g_pCrashWatcher; - return 1; /* Any exit is a failure. Normally we don't exit at all */ -} + /* Take care to emit correct exit status */ + if (sig_caught) { + signal(sig_caught, SIG_DFL); + raise(sig_caught); + } + /* I think we never end up here */ + return 0; +} -- cgit