diff options
author | Thomas Haller <thaller@redhat.com> | 2016-03-22 17:01:38 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-04-21 15:32:07 +0200 |
commit | b8a56ecc915dc1a1626562af863849feae9b7f2b (patch) | |
tree | eb64e5c5d60c52775591994d031d4bda80c729ab | |
parent | 8b92b338bcc01c0b858e05501c8fe3c0a400800b (diff) | |
download | NetworkManager-b8a56ecc915dc1a1626562af863849feae9b7f2b.tar.gz |
fixup! dns: various cleanup for new dnsmasq's D-Bus support
Use _LOGW() macro, and no longer expect that @error might be invalid
(see merge 21ff0420511975ec3669563f48c0288717c84b66).
-rw-r--r-- | src/dns-manager/nm-dns-dnsmasq.c | 86 | ||||
-rw-r--r-- | src/dns-manager/nm-dns-manager.c | 4 |
2 files changed, 43 insertions, 47 deletions
diff --git a/src/dns-manager/nm-dns-dnsmasq.c b/src/dns-manager/nm-dns-dnsmasq.c index bb1586cb6b..f0338158f4 100644 --- a/src/dns-manager/nm-dns-dnsmasq.c +++ b/src/dns-manager/nm-dns-dnsmasq.c @@ -71,12 +71,13 @@ typedef struct { /*****************************************************************************/ static void -add_dnsmasq_nameserver (GVariantBuilder *servers, +add_dnsmasq_nameserver (NMDnsDnsmasq *self, + GVariantBuilder *servers, const char *ip, const char *domain) { - nm_log_dbg (LOGD_DNS, "Adding nameserver '%s' for domain '%s'", - ip, domain); + _LOGD ("adding nameserver '%s' for domain '%s'", + ip, domain); g_return_if_fail (ip); @@ -90,7 +91,7 @@ add_dnsmasq_nameserver (GVariantBuilder *servers, } static gboolean -add_ip4_config (GVariantBuilder *servers, NMIP4Config *ip4, gboolean split) +add_ip4_config (NMDnsDnsmasq *self, GVariantBuilder *servers, NMIP4Config *ip4, gboolean split) { char buf[INET_ADDRSTRLEN]; in_addr_t addr; @@ -112,7 +113,8 @@ add_ip4_config (GVariantBuilder *servers, NMIP4Config *ip4, gboolean split) /* searches are preferred over domains */ n = nm_ip4_config_get_num_searches (ip4); for (i = 0; i < n; i++) { - add_dnsmasq_nameserver (servers, + add_dnsmasq_nameserver (self, + servers, buf, nm_ip4_config_get_search (ip4, i)); added = TRUE; @@ -122,7 +124,8 @@ add_ip4_config (GVariantBuilder *servers, NMIP4Config *ip4, gboolean split) /* If not searches, use any domains */ n = nm_ip4_config_get_num_domains (ip4); for (i = 0; i < n; i++) { - add_dnsmasq_nameserver (servers, + add_dnsmasq_nameserver (self, + servers, buf, nm_ip4_config_get_domain (ip4, i)); added = TRUE; @@ -135,7 +138,7 @@ add_ip4_config (GVariantBuilder *servers, NMIP4Config *ip4, gboolean split) domains = nm_dns_utils_get_ip4_rdns_domains (ip4); if (domains) { for (iter = domains; iter && *iter; iter++) - add_dnsmasq_nameserver (servers, buf, *iter); + add_dnsmasq_nameserver (self, servers, buf, *iter); g_strfreev (domains); added = TRUE; } @@ -146,7 +149,7 @@ add_ip4_config (GVariantBuilder *servers, NMIP4Config *ip4, gboolean split) if (!added) { for (i = 0; i < nnameservers; i++) { addr = nm_ip4_config_get_nameserver (ip4, i); - add_dnsmasq_nameserver (servers, + add_dnsmasq_nameserver (self, servers, nm_utils_inet4_ntop (addr, NULL), NULL); } } @@ -177,7 +180,7 @@ ip6_addr_to_string (const struct in6_addr *addr, const char *iface) } static void -add_global_config (GVariantBuilder *dnsmasq_servers, const NMGlobalDnsConfig *config) +add_global_config (NMDnsDnsmasq *self, GVariantBuilder *dnsmasq_servers, const NMGlobalDnsConfig *config) { guint i, j; @@ -192,16 +195,16 @@ add_global_config (GVariantBuilder *dnsmasq_servers, const NMGlobalDnsConfig *co for (j = 0; servers && servers[j]; j++) { if (!strcmp (name, "*")) - add_dnsmasq_nameserver (dnsmasq_servers, servers[j], NULL); + add_dnsmasq_nameserver (self, dnsmasq_servers, servers[j], NULL); else - add_dnsmasq_nameserver (dnsmasq_servers, servers[j], name); + add_dnsmasq_nameserver (self, dnsmasq_servers, servers[j], name); } } } static gboolean -add_ip6_config (GVariantBuilder *servers, NMIP6Config *ip6, gboolean split) +add_ip6_config (NMDnsDnsmasq *self, GVariantBuilder *servers, NMIP6Config *ip6, gboolean split) { const struct in6_addr *addr; char *buf = NULL; @@ -225,7 +228,8 @@ add_ip6_config (GVariantBuilder *servers, NMIP6Config *ip6, gboolean split) /* searches are preferred over domains */ n = nm_ip6_config_get_num_searches (ip6); for (i = 0; i < n; i++) { - add_dnsmasq_nameserver (servers, + add_dnsmasq_nameserver (self, + servers, buf, nm_ip6_config_get_search (ip6, i)); added = TRUE; @@ -235,7 +239,8 @@ add_ip6_config (GVariantBuilder *servers, NMIP6Config *ip6, gboolean split) /* If not searches, use any domains */ n = nm_ip6_config_get_num_domains (ip6); for (i = 0; i < n; i++) { - add_dnsmasq_nameserver (servers, + add_dnsmasq_nameserver (self, + servers, buf, nm_ip6_config_get_domain (ip6, i)); added = TRUE; @@ -252,7 +257,7 @@ add_ip6_config (GVariantBuilder *servers, NMIP6Config *ip6, gboolean split) addr = nm_ip6_config_get_nameserver (ip6, i); buf = ip6_addr_to_string (addr, iface); if (buf) { - add_dnsmasq_nameserver (servers, buf, NULL); + add_dnsmasq_nameserver (self, servers, buf, NULL); g_free (buf); } } @@ -270,11 +275,8 @@ dnsmasq_update_done (GObject *source, GAsyncResult *res, gpointer user_data) GVariant *response; response = g_dbus_proxy_call_finish (priv->dnsmasq, res, &error); - if (error) { - nm_log_warn (LOGD_DNS, "Dnsmasq update failed: (%d) %s", - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); - } + if (error) + _LOGW ("dnsmasq update failed: %s", error->message); if (response) g_variant_unref (response); @@ -285,10 +287,10 @@ send_dnsmasq_update (NMDnsDnsmasq *self) { NMDnsDnsmasqPrivate *priv = NM_DNS_DNSMASQ_GET_PRIVATE (self); - nm_log_dbg (LOGD_DNS, "trying to update dnsmasq nameservers"); + _LOGD ("trying to update dnsmasq nameservers"); if (!priv->servers) { - nm_log_warn (LOGD_DNS, "no nameservers list to send update"); + _LOGW ("no nameservers list to send update"); return FALSE; } @@ -304,10 +306,8 @@ send_dnsmasq_update (NMDnsDnsmasq *self) self); g_variant_builder_unref (priv->servers); priv->servers = NULL; - } else { - nm_log_warn (LOGD_DNS, "Dnsmasq not found on the bus."); - nm_log_warn (LOGD_DNS, "The nameserver update will be sent when dnsmasq appears."); - } + } else + _LOGW ("dnsmasq not found on the bus. The nameserver update will be sent when dnsmasq appears"); return TRUE; } @@ -323,11 +323,11 @@ name_owner_changed (GObject *object, owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (object)); if (owner) { - nm_log_info (LOGD_DNS, "dnsmasq appeared as %s", owner); + _LOGI ("dnsmasq appeared as %s", owner); priv->running = TRUE; g_signal_emit_by_name (self, NM_DNS_PLUGIN_APPEARED); } else { - nm_log_info (LOGD_DNS, "dnsmasq disappeared"); + _LOGI ("dnsmasq disappeared"); priv->running = FALSE; g_signal_emit_by_name (self, NM_DNS_PLUGIN_FAILED); } @@ -341,21 +341,19 @@ dnsmasq_proxy_cb (GObject *source, GAsyncResult *res, gpointer user_data) GError *error = NULL; gs_free char *owner = NULL; - nm_log_dbg (LOGD_DNS, "dnsmasq proxy creation returned"); + _LOGD ("dnsmasq proxy creation returned"); if (priv->dnsmasq) { - nm_log_dbg (LOGD_DNS, "already have an old proxy; replacing."); + _LOGD ("already have an old proxy; replacing."); g_object_unref (priv->dnsmasq); priv->dnsmasq = NULL; } priv->dnsmasq = g_dbus_proxy_new_finish (res, &error); if (!priv->dnsmasq) { - nm_log_warn (LOGD_DNS, "Failed to connect to dnsmasq via DBus: (%d) %s", - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); + _LOGW ("failed to connect to dnsmasq via DBus: %s", error->message); } else { - nm_log_dbg (LOGD_DNS, "dnsmasq proxy creation successful"); + _LOGD ("dnsmasq proxy creation successful"); g_signal_connect (priv->dnsmasq, "notify::g-name-owner", G_CALLBACK (name_owner_changed), self); @@ -374,7 +372,7 @@ get_dnsmasq_proxy (NMDnsDnsmasq *self) g_return_if_fail (!priv->dnsmasq); - nm_log_dbg (LOGD_DNS, "retrieving dnsmasq proxy"); + _LOGD ("retrieving dnsmasq proxy"); if (!priv->dnsmasq) { g_dbus_proxy_new (priv->connection, @@ -405,7 +403,7 @@ start_dnsmasq (NMDnsDnsmasq *self) * anything more. */ if (priv->running) { - nm_log_dbg (LOGD_DNS, "dnsmasq is already running"); + _LOGD ("dnsmasq is already running"); return TRUE; } @@ -483,30 +481,30 @@ update (NMDnsPlugin *plugin, priv->servers = g_variant_builder_new (G_VARIANT_TYPE ("aas")); if (global_config) - add_global_config (priv->servers, global_config); + add_global_config (self, priv->servers, global_config); else { /* Use split DNS for VPN configs */ for (iter = (GSList *) vpn_configs; iter; iter = g_slist_next (iter)) { if (NM_IS_IP4_CONFIG (iter->data)) - add_ip4_config (priv->servers, NM_IP4_CONFIG (iter->data), TRUE); + add_ip4_config (self, priv->servers, NM_IP4_CONFIG (iter->data), TRUE); else if (NM_IS_IP6_CONFIG (iter->data)) - add_ip6_config (priv->servers, NM_IP6_CONFIG (iter->data), TRUE); + add_ip6_config (self, priv->servers, NM_IP6_CONFIG (iter->data), TRUE); } /* Now add interface configs without split DNS */ for (iter = (GSList *) dev_configs; iter; iter = g_slist_next (iter)) { if (NM_IS_IP4_CONFIG (iter->data)) - add_ip4_config (priv->servers, NM_IP4_CONFIG (iter->data), FALSE); + add_ip4_config (self, priv->servers, NM_IP4_CONFIG (iter->data), FALSE); else if (NM_IS_IP6_CONFIG (iter->data)) - add_ip6_config (priv->servers, NM_IP6_CONFIG (iter->data), FALSE); + add_ip6_config (self, priv->servers, NM_IP6_CONFIG (iter->data), FALSE); } /* And any other random configs */ for (iter = (GSList *) other_configs; iter; iter = g_slist_next (iter)) { if (NM_IS_IP4_CONFIG (iter->data)) - add_ip4_config (priv->servers, NM_IP4_CONFIG (iter->data), FALSE); + add_ip4_config (self, priv->servers, NM_IP4_CONFIG (iter->data), FALSE); else if (NM_IS_IP6_CONFIG (iter->data)) - add_ip6_config (priv->servers, NM_IP6_CONFIG (iter->data), FALSE); + add_ip6_config (self, priv->servers, NM_IP6_CONFIG (iter->data), FALSE); } } @@ -605,7 +603,7 @@ nm_dns_dnsmasq_init (NMDnsDnsmasq *self) priv->connection = nm_bus_manager_get_connection (priv->dbus_mgr); if (!priv->connection) - nm_log_warn (LOGD_DNS, "Could not get the system bus to speak to dnsmasq."); + _LOGW ("could not get the system bus to speak to dnsmasq"); else get_dnsmasq_proxy (self); } diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c index 455fcdb25b..54278a26c3 100644 --- a/src/dns-manager/nm-dns-manager.c +++ b/src/dns-manager/nm-dns-manager.c @@ -1126,9 +1126,7 @@ plugin_appeared (NMDnsPlugin *plugin, gpointer user_data) /* Try to update DNS again; since it's now available on the bus this * might work. */ if (!update_dns (self, FALSE, &error)) { - nm_log_warn (LOGD_DNS, "could not commit DNS changes: (%d) %s", - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); + _LOGW ("could not commit DNS changes: %s", error->message); g_clear_error (&error); } } |