From e21db61b6de1e81a83fcbfd489294e81c3cf3dc8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 3 Aug 2021 09:30:47 +0200 Subject: [PATCH] dispatcher: setup signal handler as first The very first and the very last thing we want to do is register (unregister) the signal handler. --- src/nm-dispatcher/nm-dispatcher.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/nm-dispatcher/nm-dispatcher.c b/src/nm-dispatcher/nm-dispatcher.c index ad566c0db7..17e8a5d1c8 100644 --- a/src/nm-dispatcher/nm-dispatcher.c +++ b/src/nm-dispatcher/nm-dispatcher.c @@ -996,15 +996,15 @@ main(int argc, char **argv) guint dbus_regist_id = 0; guint dbus_own_name_id = 0; + source_term = nm_g_unix_signal_add_source(SIGTERM, signal_handler, GINT_TO_POINTER(SIGTERM)); + source_int = nm_g_unix_signal_add_source(SIGINT, signal_handler, GINT_TO_POINTER(SIGINT)); + if (!parse_command_line(&argc, &argv, &error)) { _LOG_X_W("Error parsing command line arguments: %s", error->message); gl.exit_with_failure = TRUE; goto done; } - source_term = nm_g_unix_signal_add_source(SIGTERM, signal_handler, GINT_TO_POINTER(SIGTERM)); - source_int = nm_g_unix_signal_add_source(SIGINT, signal_handler, GINT_TO_POINTER(SIGINT)); - if (gl.debug) { if (!g_getenv("G_MESSAGES_DEBUG")) { /* we log our regular messages using g_debug() and g_info(). @@ -1084,13 +1084,14 @@ done: nm_clear_pointer(&gl.requests_waiting, g_queue_free); - nm_clear_g_source_inst(&source_term); - nm_clear_g_source_inst(&source_int); nm_clear_g_source_inst(&gl.quit_source); g_clear_object(&gl.dbus_connection); if (!gl.debug) logging_shutdown(); + nm_clear_g_source_inst(&source_term); + nm_clear_g_source_inst(&source_int); + return gl.exit_with_failure ? 1 : 0; }