From c5a6b1fe2aba42134314f5af4ee205833bfba3f8 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Wed, 6 Oct 2010 15:54:28 +0200 Subject: [PATCH] Do the SIGTERM cleanup outside the signal handler --- src/main.cpp | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 54022da..4decd4a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,7 @@ Updater::Ptr updater; volatile bool is_online = false; volatile bool webcheck_enabled = false; volatile bool need_config_reload = false; +volatile bool exit_now = false; /** * Checks if a bpdyndnsd process is already running. @@ -139,8 +140,7 @@ int shutdown() void terminate(int param) { updater->get_logger()->print_caught_sigterm(); - - exit(shutdown()); + exit_now = true; } /*lint !e715 */ @@ -161,7 +161,6 @@ void switch_to_offline(int param) */ void reload_config(int param) { - updater->get_logger()->print_caught_sighup(); need_config_reload = true; } /*lint !e715 */ @@ -312,6 +311,10 @@ int main(int argc, char *argv[]) is_online = !updater->get_config()->get_start_offline(); webcheck_enabled = updater->get_config()->get_webcheck_enabled(); + // One shot run if daemon mode is disabled + if (updater->get_config()->get_daemon_mode() != 1) + exit_now = true; + // service processing starts here do { @@ -332,6 +335,7 @@ int main(int argc, char *argv[]) if (need_config_reload) { + updater->get_logger()->print_caught_sighup(); need_config_reload = false; if ( updater->reload_config() != 0 ) @@ -342,10 +346,9 @@ int main(int argc, char *argv[]) } // Snore, snore... don't hog the cpu if we are in daemon_mode. - if ( updater->get_config()->get_daemon_mode() == 1 ) + if ( !exit_now ) sleep(10); /*lint !e534 */ - - }while ( updater->get_config()->get_daemon_mode() == 1 ); + } while ( !exit_now ); // Serialize services to save their actual state. if ( shutdown() != 0 ) -- 1.7.1