mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-23 04:40:27 +01:00
core: nm_singleton_instance_register() of NMManager instance
Register the singleton instance of NMManager as we do for other singletons. That way, we get automatic destruction and the singleton instance get's properly cleared (when the instance gets destroyed).
This commit is contained in:
parent
80117aa676
commit
31cde10b69
2 changed files with 12 additions and 11 deletions
17
src/main.c
17
src/main.c
|
|
@ -249,7 +249,6 @@ main (int argc, char *argv[])
|
|||
{
|
||||
gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE;
|
||||
gboolean success = FALSE;
|
||||
NMManager *manager = NULL;
|
||||
NMConfig *config;
|
||||
GError *error = NULL;
|
||||
gboolean wrote_pidfile = FALSE;
|
||||
|
|
@ -402,10 +401,10 @@ main (int argc, char *argv[])
|
|||
|
||||
nm_auth_manager_setup (nm_config_get_auth_polkit (config));
|
||||
|
||||
manager = nm_manager_setup (global_opt.state_file,
|
||||
net_enabled,
|
||||
wifi_enabled,
|
||||
wwan_enabled);
|
||||
nm_manager_setup (global_opt.state_file,
|
||||
net_enabled,
|
||||
wifi_enabled,
|
||||
wwan_enabled);
|
||||
|
||||
if (!nm_bus_manager_get_connection (nm_bus_manager_get ())) {
|
||||
nm_log_warn (LOGD_CORE, "Failed to connect to D-Bus; only private bus is available");
|
||||
|
|
@ -424,9 +423,9 @@ main (int argc, char *argv[])
|
|||
|
||||
nm_dispatcher_init ();
|
||||
|
||||
g_signal_connect (manager, NM_MANAGER_CONFIGURE_QUIT, G_CALLBACK (manager_configure_quit), config);
|
||||
g_signal_connect (nm_manager_get (), NM_MANAGER_CONFIGURE_QUIT, G_CALLBACK (manager_configure_quit), config);
|
||||
|
||||
if (!nm_manager_start (manager, &error)) {
|
||||
if (!nm_manager_start (nm_manager_get (), &error)) {
|
||||
nm_log_err (LOGD_CORE, "failed to initialize: %s", error->message);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -449,11 +448,9 @@ main (int argc, char *argv[])
|
|||
if (configure_and_quit == FALSE)
|
||||
g_main_loop_run (main_loop);
|
||||
|
||||
nm_manager_stop (manager);
|
||||
nm_manager_stop (nm_manager_get ());
|
||||
|
||||
done:
|
||||
g_clear_object (&manager);
|
||||
|
||||
if (global_opt.pidfile && wrote_pidfile)
|
||||
unlink (global_opt.pidfile);
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@
|
|||
#include "nm-config.h"
|
||||
#include "nm-audit-manager.h"
|
||||
#include "nm-dbus-compat.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
#include "nmdbus-manager.h"
|
||||
|
||||
|
|
@ -4705,7 +4706,7 @@ dbus_connection_changed_cb (NMBusManager *dbus_mgr,
|
|||
|
||||
/**********************************************************************/
|
||||
|
||||
static NMManager *singleton_instance = NULL;
|
||||
NM_DEFINE_SINGLETON_REGISTER (NMManager);
|
||||
|
||||
NMManager *
|
||||
nm_manager_get (void)
|
||||
|
|
@ -4806,6 +4807,9 @@ nm_manager_setup (const char *state_file,
|
|||
rfkill_change (priv->radio_states[RFKILL_TYPE_WLAN].desc, RFKILL_TYPE_WLAN, initial_wifi_enabled);
|
||||
rfkill_change (priv->radio_states[RFKILL_TYPE_WWAN].desc, RFKILL_TYPE_WWAN, initial_wwan_enabled);
|
||||
|
||||
nm_singleton_instance_register ();
|
||||
nm_log_dbg (LOGD_CORE, "setup %s singleton (%p)", "NMManager", singleton_instance);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue