diff options
author | Thomas Haller <thaller@redhat.com> | 2021-08-03 10:12:09 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-08-04 09:41:10 +0200 |
commit | 273491922e632d3568a11026e2d93e1725676212 (patch) | |
tree | f734393fde584d942d4701a5ee5bb815e3541dca | |
parent | 442428dbbf3df5d372b562344680dedc5a555b86 (diff) | |
download | NetworkManager-273491922e632d3568a11026e2d93e1725676212.tar.gz |
dispatcher: use nm_g_bus_get_blocking() to create GDBusConnection
The difference is that nm_g_bus_get_blocking() iterates the GMainContext
of the caller, and thus it can process and handle SIGTERM signals.
Calling g_bus_get_sync() does not iterate the context, and we cannot
handle or detect early cancellation.
-rw-r--r-- | src/nm-dispatcher/nm-dispatcher.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/nm-dispatcher/nm-dispatcher.c b/src/nm-dispatcher/nm-dispatcher.c index e160d6c94f..039815d313 100644 --- a/src/nm-dispatcher/nm-dispatcher.c +++ b/src/nm-dispatcher/nm-dispatcher.c @@ -18,6 +18,7 @@ #include <arpa/inet.h> #include "libnm-core-aux-extern/nm-dispatcher-api.h" +#include "libnm-glib-aux/nm-dbus-aux.h" #include "nm-dispatcher-utils.h" /*****************************************************************************/ @@ -1021,14 +1022,21 @@ main(int argc, char **argv) } else logging_setup(); - gl.dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + gl.dbus_connection = nm_g_bus_get_blocking(gl.quit_cancellable, &error); if (!gl.dbus_connection) { - _LOG_X_W("Could not get the system bus (%s). Make sure the message bus daemon is running!", - error->message); - gl.exit_with_failure = TRUE; + if (!nm_utils_error_is_cancelled(error)) { + _LOG_X_W("dbus: failure to get D-Bus connection: %s", error->message); + gl.exit_with_failure = TRUE; + } goto done; } + /* On bus-disconnect, GDBus will raise(SIGTERM), which we handle like a + * regular request to quit. */ + g_dbus_connection_set_exit_on_close(gl.dbus_connection, TRUE); + + _LOG_X_D("dbus: unique name: %s", g_dbus_connection_get_unique_name(gl.dbus_connection)); + gl.requests_waiting = g_queue_new(); dbus_regist_id = |