diff options
author | Thomas Haller <thaller@redhat.com> | 2015-01-06 13:15:43 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-01-08 15:46:21 +0100 |
commit | 835a08910d92bbf11e6150b97bd721c939b5d9c1 (patch) | |
tree | fb54dd5e2f876d575a3340354bbf085f36ae4f50 | |
parent | d2e25135d5833faf621d1ed546c5db78ccc19f35 (diff) | |
download | NetworkManager-th/singleton-bgo742450.tar.gz |
dbus: destroy singleton instance of NMDBusManager on exitth/singleton-bgo742450
Don't have the singleton instance of NMDBusManager owned by
the main function. Instead use NM_DEFINE_SINGLETON_DESTRUCTOR()
which also logs what's happening.
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/nm-dbus-manager.c | 5 |
2 files changed, 6 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c index 88d16144d9..0901747989 100644 --- a/src/main.c +++ b/src/main.c @@ -200,7 +200,6 @@ main (int argc, char *argv[]) gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE, wimax_enabled = TRUE; gboolean success, show_version = FALSE; NMManager *manager = NULL; - gs_unref_object NMDBusManager *dbus_mgr = NULL; gs_unref_object NMSettings *settings = NULL; gs_unref_object NMConfig *config = NULL; GError *error = NULL; @@ -387,10 +386,6 @@ main (int argc, char *argv[]) nm_auth_manager_setup (nm_config_get_auth_polkit (config)); - /* Initialize our DBus service & connection */ - dbus_mgr = nm_dbus_manager_get (); - g_assert (dbus_mgr != NULL); - nm_dispatcher_init (); settings = nm_settings_new (&error); @@ -413,7 +408,7 @@ main (int argc, char *argv[]) goto done; } - if (!nm_dbus_manager_get_connection (dbus_mgr)) { + if (!nm_dbus_manager_get_connection (nm_dbus_manager_get ())) { #if HAVE_DBUS_GLIB_100 nm_log_warn (LOGD_CORE, "Failed to connect to D-Bus; only private bus is available"); #else @@ -422,7 +417,7 @@ main (int argc, char *argv[]) #endif } else { /* Start our DBus service */ - if (!nm_dbus_manager_start_service (dbus_mgr)) { + if (!nm_dbus_manager_start_service (nm_dbus_manager_get ())) { nm_log_err (LOGD_CORE, "failed to start the dbus service."); goto done; } diff --git a/src/nm-dbus-manager.c b/src/nm-dbus-manager.c index 165071227f..7d314f810d 100644 --- a/src/nm-dbus-manager.c +++ b/src/nm-dbus-manager.c @@ -78,15 +78,18 @@ static void nm_dbus_manager_cleanup (NMDBusManager *self, gboolean dispose); static void start_reconnection_timeout (NMDBusManager *self); static void object_destroyed (NMDBusManager *self, gpointer object); +NM_DEFINE_SINGLETON_DESTRUCTOR (NMDBusManager); +NM_DEFINE_SINGLETON_WEAK_REF (NMDBusManager); + NMDBusManager * nm_dbus_manager_get (void) { - static NMDBusManager *singleton_instance = NULL; static gsize once = 0; if (g_once_init_enter (&once)) { singleton_instance = (NMDBusManager *) g_object_new (NM_TYPE_DBUS_MANAGER, NULL); g_assert (singleton_instance); + nm_singleton_instance_weak_ref_register (); if (!nm_dbus_manager_init_bus (singleton_instance)) start_reconnection_timeout (singleton_instance); g_once_init_leave (&once, 1); |