From 213a3a4d2e0aaccc3d07bdd043d374ac660ce209 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 12 Mar 2013 14:01:43 -0400 Subject: [PATCH] core: don't pass config data to NMDHCPManager and NMDnsManager Rather than passing specific bits of data to NMDHCPManager and NMDnsManager, just let them call nm_config_get() and then get the data themselves. Also, remove the GError argument from nm_dhcp_manager_new(), since the function never returned NULL. This in turn means there is no longer any need for a distinction between nm_dhcp_manager_new() and nm_dhcp_manager_get(), so remove the former. --- src/dhcp-manager/Makefile.am | 2 ++ src/dhcp-manager/nm-dhcp-manager.c | 22 +++++++++++----------- src/dhcp-manager/nm-dhcp-manager.h | 3 --- src/dns-manager/Makefile.am | 2 ++ src/dns-manager/nm-dns-manager.c | 6 +++++- src/dns-manager/nm-dns-manager.h | 2 +- src/main.c | 4 ++-- src/nm-policy.c | 8 ++++---- 8 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/dhcp-manager/Makefile.am b/src/dhcp-manager/Makefile.am index 40a0583411..86fafa2e6a 100644 --- a/src/dhcp-manager/Makefile.am +++ b/src/dhcp-manager/Makefile.am @@ -7,6 +7,7 @@ INCLUDES = \ -I${top_builddir}/src/generated \ -I${top_srcdir}/src/generated \ -I${top_srcdir}/src/logging \ + -I${top_srcdir}/src/config \ -I${top_srcdir}/src/posix-signals \ -I${top_builddir}/libnm-util \ -I${top_srcdir}/libnm-util \ @@ -61,6 +62,7 @@ libdhcp_manager_la_CPPFLAGS = \ libdhcp_manager_la_LIBADD = \ $(top_builddir)/src/logging/libnm-logging.la \ + $(top_builddir)/src/config/libnm-config.la \ $(top_builddir)/src/posix-signals/libnm-posix-signals.la \ $(builddir)/libdhcp-dhclient.la \ $(DBUS_LIBS) \ diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c index c1ac648926..fa69327d7a 100644 --- a/src/dhcp-manager/nm-dhcp-manager.c +++ b/src/dhcp-manager/nm-dhcp-manager.c @@ -41,6 +41,7 @@ #include "nm-logging.h" #include "nm-dbus-manager.h" #include "nm-hostname-provider.h" +#include "nm-config.h" #include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" @@ -293,24 +294,30 @@ get_client_type (const char *client, GError **error) } NMDHCPManager * -nm_dhcp_manager_new (const char *client, GError **error) +nm_dhcp_manager_get (void) { NMDHCPManagerPrivate *priv; DBusGConnection *g_connection; + const char *client; + GError *error = NULL; - g_warn_if_fail (singleton == NULL); + if (singleton) + return g_object_ref (singleton); singleton = g_object_new (NM_TYPE_DHCP_MANAGER, NULL); priv = NM_DHCP_MANAGER_GET_PRIVATE (singleton); /* Client-specific setup */ - priv->client_type = get_client_type (client, error); + client = nm_config_get_dhcp_client (nm_config_get ()); + priv->client_type = get_client_type (client, &error); if (priv->client_type == NM_TYPE_DHCP_DHCLIENT) priv->get_lease_config_func = nm_dhcp_dhclient_get_lease_config; else if (priv->client_type == NM_TYPE_DHCP_DHCPCD) priv->get_lease_config_func = nm_dhcp_dhcpcd_get_lease_config; else { - nm_log_warn (LOGD_DHCP, "No usable DHCP client found! DHCP configurations will fail."); + nm_log_warn (LOGD_DHCP, "No usable DHCP client found (%s)! DHCP configurations will fail.", + error->message); + g_error_free (error); } priv->clients = g_hash_table_new_full (g_direct_hash, g_direct_equal, @@ -590,13 +597,6 @@ nm_dhcp_manager_test_ip4_options_to_config (const char *dhcp_client, /***************************************************/ -NMDHCPManager * -nm_dhcp_manager_get (void) -{ - g_warn_if_fail (singleton != NULL); - return g_object_ref (singleton); -} - static void nm_dhcp_manager_init (NMDHCPManager *manager) { diff --git a/src/dhcp-manager/nm-dhcp-manager.h b/src/dhcp-manager/nm-dhcp-manager.h index a29a33fdbd..e61468e3cd 100644 --- a/src/dhcp-manager/nm-dhcp-manager.h +++ b/src/dhcp-manager/nm-dhcp-manager.h @@ -93,7 +93,4 @@ NMIP4Config *nm_dhcp_manager_test_ip4_options_to_config (const char *dhcp_client GHashTable *options, const char *reason); -/* Only for main.c */ -NMDHCPManager *nm_dhcp_manager_new (const char *client, GError **error); - #endif /* NM_DHCP_MANAGER_H */ diff --git a/src/dns-manager/Makefile.am b/src/dns-manager/Makefile.am index e6c2ff2209..9cf1c0e00f 100644 --- a/src/dns-manager/Makefile.am +++ b/src/dns-manager/Makefile.am @@ -1,5 +1,6 @@ INCLUDES = \ -I${top_srcdir}/src/logging \ + -I${top_srcdir}/src/config \ -I${top_srcdir}/src/posix-signals \ -I${top_srcdir}/libnm-util \ -I${top_builddir}/libnm-util \ @@ -30,6 +31,7 @@ libdns_manager_la_CPPFLAGS = \ libdns_manager_la_LIBADD = \ $(top_builddir)/src/logging/libnm-logging.la \ + $(top_builddir)/src/config/libnm-config.la \ $(top_builddir)/src/posix-signals/libnm-posix-signals.la \ $(LIBNL_LIBS) \ $(DBUS_LIBS) \ diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c index fb426637ff..742ab82e05 100644 --- a/src/dns-manager/nm-dns-manager.c +++ b/src/dns-manager/nm-dns-manager.c @@ -42,6 +42,7 @@ #include "nm-logging.h" #include "NetworkManagerUtils.h" #include "nm-posix-signals.h" +#include "nm-config.h" #include "nm-dns-plugin.h" #include "nm-dns-dnsmasq.h" @@ -1076,13 +1077,16 @@ load_plugins (NMDnsManager *self, const char **plugins) /******************************************************************/ NMDnsManager * -nm_dns_manager_get (const char **plugins) +nm_dns_manager_get (void) { static NMDnsManager * singleton = NULL; + const char **plugins; if (!singleton) { singleton = NM_DNS_MANAGER (g_object_new (NM_TYPE_DNS_MANAGER, NULL)); g_assert (singleton); + + plugins = nm_config_get_dns_plugins (nm_config_get ()); load_plugins (singleton, plugins); } else g_object_ref (singleton); diff --git a/src/dns-manager/nm-dns-manager.h b/src/dns-manager/nm-dns-manager.h index 0fd4c198b9..c38fc7e412 100644 --- a/src/dns-manager/nm-dns-manager.h +++ b/src/dns-manager/nm-dns-manager.h @@ -67,7 +67,7 @@ typedef struct { GType nm_dns_manager_get_type (void); -NMDnsManager * nm_dns_manager_get (const char **plugins); +NMDnsManager * nm_dns_manager_get (void); /* Allow changes to be batched together */ void nm_dns_manager_begin_updates (NMDnsManager *mgr, const char *func); diff --git a/src/main.c b/src/main.c index dff1bdb261..9210d7332b 100644 --- a/src/main.c +++ b/src/main.c @@ -493,7 +493,7 @@ main (int argc, char *argv[]) goto done; } - dns_mgr = nm_dns_manager_get (nm_config_get_dns_plugins (config)); + dns_mgr = nm_dns_manager_get (); if (!dns_mgr) { nm_log_err (LOGD_CORE, "failed to start the DNS manager."); goto done; @@ -535,7 +535,7 @@ main (int argc, char *argv[]) } /* Initialize DHCP manager */ - dhcp_mgr = nm_dhcp_manager_new (nm_config_get_dhcp_client (config), &error); + dhcp_mgr = nm_dhcp_manager_get (); if (!dhcp_mgr) { nm_log_err (LOGD_CORE, "failed to start the DHCP manager: %s.", error->message); goto done; diff --git a/src/nm-policy.c b/src/nm-policy.c index 5ab7a35449..8c034ea6a1 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -852,7 +852,7 @@ update_routing_and_dns (NMPolicy *policy, gboolean force_update) { NMDnsManager *mgr; - mgr = nm_dns_manager_get (NULL); + mgr = nm_dns_manager_get (); nm_dns_manager_begin_updates (mgr, __func__); update_ip4_dns (policy, mgr); @@ -1609,7 +1609,7 @@ vpn_connection_activated (NMPolicy *policy, NMVPNConnection *vpn) NMIP6Config *ip6_config; const char *ip_iface; - mgr = nm_dns_manager_get (NULL); + mgr = nm_dns_manager_get (); nm_dns_manager_begin_updates (mgr, __func__); ip_iface = nm_vpn_connection_get_ip_iface (vpn); @@ -1640,7 +1640,7 @@ vpn_connection_deactivated (NMPolicy *policy, NMVPNConnection *vpn) const char *ip_iface; NMDevice *parent; - mgr = nm_dns_manager_get (NULL); + mgr = nm_dns_manager_get (); nm_dns_manager_begin_updates (mgr, __func__); ip_iface = nm_vpn_connection_get_ip_iface (vpn); @@ -1987,7 +1987,7 @@ nm_policy_new (NMManager *manager, NMSettings *settings) G_CALLBACK (firewall_started), policy); policy->fw_started_id = id; - policy->dns_manager = nm_dns_manager_get (NULL); + policy->dns_manager = nm_dns_manager_get (); policy->config_changed_id = g_signal_connect (policy->dns_manager, "config-changed", G_CALLBACK (dns_config_changed), policy);