2008-08-12 Tambet Ingo <tambet@gmail.com>
authorTambet Ingo <tambet@gmail.com>
Tue, 12 Aug 2008 08:05:16 +0000 (08:05 +0000)
committerTambet Ingo <tambet@gmail.com>
Tue, 12 Aug 2008 08:05:16 +0000 (08:05 +0000)
* src/backends/*: Get rid of nm_system_should_modify_resolv_conf().

* src/named-manager/nm-named-manager.c (rewrite_resolv_conf): Calculate
the composite result of all the IP4 configurations and call a distro
specific update_resolv_conf().
(update_resolv_conf): Implement one for directly writing to
/etc/resolv.conf and one for opensuse to call netconfig.

git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3931 4912f4e0-d625-0410-9fb7-b9a5a253dbdc

18 files changed:
ChangeLog
src/NetworkManagerPolicy.c
src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerDebian.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerMandriva.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerSuSE.c
src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
src/nm-device.c

index 2429c74..870a05b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-08-12  Tambet Ingo  <tambet@gmail.com>
+
+       * src/backends/*: Get rid of nm_system_should_modify_resolv_conf().
+
+       * src/named-manager/nm-named-manager.c (rewrite_resolv_conf): Calculate
+       the composite result of all the IP4 configurations and call a distro
+       specific update_resolv_conf().
+       (update_resolv_conf): Implement one for directly writing to 
+       /etc/resolv.conf and one for opensuse to call netconfig.
+
 2008-08-11  Dan Williams  <dcbw@redhat.com>
 
        * src/ppp-manager/nm-ppp-manager.c
index 631068f..ea5d5e1 100644 (file)
@@ -122,7 +122,6 @@ update_routing_and_dns (NMPolicy *policy, gboolean force_update)
        NMActRequest *best_req = NULL;
        GSList *devices, *iter;
        NMNamedManager *named_mgr;
-       NMIP4Config *config;
 
        devices = nm_manager_get_devices (policy->manager);
        for (iter = devices; iter; iter = g_slist_next (iter)) {
@@ -196,8 +195,10 @@ update_routing_and_dns (NMPolicy *policy, gboolean force_update)
        }
 
        named_mgr = nm_named_manager_get ();
-       config = nm_device_get_ip4_config (best);
-       nm_named_manager_add_ip4_config (named_mgr, config, NM_NAMED_IP_CONFIG_TYPE_BEST_DEVICE);
+       nm_named_manager_add_ip4_config (named_mgr,
+                                                                        nm_device_get_ip_iface (best),
+                                                                        nm_device_get_ip4_config (best),
+                                                                        NM_NAMED_IP_CONFIG_TYPE_BEST_DEVICE);
        g_object_unref (named_mgr);
 
        /* Now set new default active connection _after_ updating DNS info, so that
index bf6b11d..5793963 100644 (file)
@@ -385,7 +385,7 @@ nm_system_vpn_device_set_from_ip4_config (NMDevice *active_device,
 
 out:
        named_mgr = nm_named_manager_get ();
-       nm_named_manager_add_ip4_config (named_mgr, config, NM_NAMED_IP_CONFIG_TYPE_VPN);
+       nm_named_manager_add_ip4_config (named_mgr, iface, config, NM_NAMED_IP_CONFIG_TYPE_VPN);
        g_object_unref (named_mgr);
 
        return TRUE;
@@ -406,7 +406,7 @@ gboolean nm_system_vpn_device_unset_from_ip4_config (NMDevice *active_device, co
        g_return_val_if_fail (config != NULL, FALSE);
 
        named_mgr = nm_named_manager_get ();
-       nm_named_manager_remove_ip4_config (named_mgr, config);
+       nm_named_manager_remove_ip4_config (named_mgr, iface, config);
        g_object_unref (named_mgr);
 
        return TRUE;
index 75c550b..496a314 100644 (file)
@@ -66,6 +66,4 @@ void                  nm_system_set_hostname (NMIP4Config *config);
 
 gboolean               nm_system_device_set_mtu (const char *iface, guint32 mtu);
 
-gboolean               nm_system_should_modify_resolv_conf (void);
-
 #endif
index cc847eb..a7a4fe4 100644 (file)
@@ -79,16 +79,6 @@ void nm_system_update_dns (void)
 }
 
 /*
- * nm_system_should_modify_resolv_conf
- *
- * Can NM update resolv.conf, or is it locked down?
- */
-gboolean nm_system_should_modify_resolv_conf (void)
-{
-       return TRUE;
-}
-
-/*
  * nm_system_set_hostname
  *
  * set the hostname
index 0ea3b6d..d9e2ead 100644 (file)
@@ -73,14 +73,3 @@ void nm_system_update_dns (void)
 void nm_system_set_hostname (NMIP4Config *config)
 {
 }
-
-/*
- * nm_system_should_modify_resolv_conf
- *
- * Can NM update resolv.conf, or is it locked down?
- */
-gboolean nm_system_should_modify_resolv_conf (void)
-{
-       return TRUE;
-}
-
index 7eadfa9..47a19f5 100644 (file)
@@ -71,14 +71,3 @@ void nm_system_update_dns (void)
 void nm_system_set_hostname (NMIP4Config *config)
 {
 }
-
-/*
- * nm_system_should_modify_resolv_conf
- *
- * Can NM update resolv.conf, or is it locked down?
- */
-gboolean nm_system_should_modify_resolv_conf (void)
-{
-       return TRUE;
-}
-
index b6a9d3b..ed4b02e 100644 (file)
@@ -238,14 +238,3 @@ NMIP4Config *nm_generic_device_new_ip4_system_config (NMDevice *dev)
 void nm_generic_set_hostname (NMIP4Config *config)
 {
 }
-
-/*
- * nm_generic_should_modify_resolv_conf
- *
- * Can NM update resolv.conf, or is it locked down?
- */
-gboolean nm_generic_should_modify_resolv_conf (void)
-{
-       return TRUE;
-}
-
index 0cb88bc..8c2a817 100644 (file)
@@ -52,6 +52,4 @@ gboolean              nm_generic_device_set_up_down_with_iface                (NMDevice *dev, const char *
 
 void                   nm_generic_set_hostname (NMIP4Config *config);
 
-gboolean               nm_generic_should_modify_resolv_conf (void);
-
 #endif
index ef4abbe..a34ba3f 100644 (file)
@@ -80,15 +80,3 @@ void nm_system_update_dns (void)
 void nm_system_set_hostname (NMIP4Config *config)
 {
 }
-
-/*
- * nm_system_should_modify_resolv_conf
- *
- * Can NM update resolv.conf, or is it locked down?
- */
-gboolean nm_system_should_modify_resolv_conf (void)
-{
-       return TRUE;
-}
-
-
index bf4e63e..c9d79f0 100644 (file)
@@ -74,15 +74,3 @@ void nm_system_update_dns (void)
 void nm_system_set_hostname (NMIP4Config *config)
 {
 }
-
-
-/*
- * nm_system_should_modify_resolv_conf
- *
- * Can NM update resolv.conf, or is it locked down?
- */
-gboolean nm_system_should_modify_resolv_conf (void)
-{
-       return TRUE;
-}
-
index b1fdc0a..a2ea9ca 100644 (file)
@@ -73,15 +73,3 @@ void nm_system_update_dns (void)
 void nm_system_set_hostname (NMIP4Config *config)
 {
 }
-
-
-/*
- * nm_system_should_modify_resolv_conf
- *
- * Can NM update resolv.conf, or is it locked down?
- */
-gboolean nm_system_should_modify_resolv_conf (void)
-{
-       return TRUE;
-}
-
index fd7cc45..50e47f2 100644 (file)
@@ -72,15 +72,3 @@ void nm_system_update_dns (void)
 void nm_system_set_hostname (NMIP4Config *config)
 {
 }
-
-
-/*
- * nm_system_should_modify_resolv_conf
- *
- * Can NM update resolv.conf, or is it locked down?
- */
-gboolean nm_system_should_modify_resolv_conf (void)
-{
-       return TRUE;
-}
-
index 191c5ac..16c3c17 100644 (file)
@@ -69,14 +69,3 @@ void nm_system_update_dns (void)
 void nm_system_set_hostname (NMIP4Config *config)
 {
 }
-
-/*
- * nm_system_should_modify_resolv_conf
- *
- * Can NM update resolv.conf, or is it locked down?
- */
-gboolean nm_system_should_modify_resolv_conf (void)
-{
-       return TRUE;
-}
-
index 36934b6..5ba7e8d 100644 (file)
@@ -131,36 +131,3 @@ out_close:
 out_gfree:
        g_free (filename);
 }
-
-/*
- * nm_system_should_modify_resolv_conf
- *
- * Can NM update resolv.conf, or is it locked down?
- */
-gboolean nm_system_should_modify_resolv_conf (void)
-{
-       char *name, *buf;
-       shvarFile *file;
-       gboolean ret = TRUE;
-
-       name = g_strdup_printf (SYSCONFDIR"/sysconfig/network/dhcp");
-       file = svNewFile (name);
-       if (!file)
-               goto out_gfree;
-
-       buf = svGetValue (file, "DHCLIENT_MODIFY_RESOLV_CONF");
-       if (!buf)
-               goto out_close;
-
-       if (strcmp (buf, "no") == 0)
-               ret = FALSE;
-
-       free (buf);
-out_close:
-       svCloseFile (file);
-out_gfree:
-       g_free (name);
-
-       return ret;
-}
-
index 0162ea9..dc4a0b9 100644 (file)
@@ -1,3 +1,5 @@
+/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+
 /*
  *  Copyright (C) 2004 - 2008 Red Hat, Inc.
  *
@@ -26,6 +28,8 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <arpa/inet.h>
+#include <sys/types.h>
+#include <unistd.h>
 #include <glib.h>
 
 #include <glib/gi18n.h>
@@ -85,50 +89,6 @@ nm_named_manager_error_quark (void)
        return quark;
 }
 
-static char *
-compute_nameservers (NMIP4Config *config)
-{
-       int i, num;
-       GString *str = NULL;
-
-       g_return_val_if_fail (config != NULL, NULL);
-
-       num = nm_ip4_config_get_num_nameservers (config);
-       if (num == 0)
-               return NULL;
-
-       str = g_string_new ("");
-       for (i = 0; i < num; i++) {
-               #define ADDR_BUF_LEN 50
-               struct in_addr addr;
-               char *buf;
-
-               addr.s_addr = nm_ip4_config_get_nameserver (config, i);
-               buf = g_malloc0 (ADDR_BUF_LEN);
-               if (!buf)
-                       continue;
-
-               if (!inet_ntop (AF_INET, &addr, buf, ADDR_BUF_LEN))
-                       nm_warning ("%s: error converting IP4 address 0x%X",
-                                   __func__, ntohl (addr.s_addr));
-
-               if (i == 3) {
-                       g_string_append (str, "\n# ");
-                       g_string_append (str, _("NOTE: the glibc resolver does not support more than 3 nameservers."));
-                       g_string_append (str, "\n# ");
-                       g_string_append (str, _("The nameservers listed below may not be recognized."));
-                       g_string_append_c (str, '\n');
-               }
-
-               g_string_append (str, "nameserver ");
-               g_string_append (str, buf);
-               g_string_append_c (str, '\n');
-               g_free (buf);
-       }
-
-       return g_string_free (str, FALSE);
-}
-
 static void
 merge_one_ip4_config (NMIP4Config *dst, NMIP4Config *src)
 {
@@ -155,49 +115,221 @@ merge_one_ip4_config (NMIP4Config *dst, NMIP4Config *src)
        }
 }
 
+#if defined(TARGET_SUSE)
+/**********************************/
+/* SUSE */
+
+static void
+netconfig_child_setup (gpointer user_data G_GNUC_UNUSED)
+{
+       pid_t pid = getpid ();
+       setpgid (pid, pid);
+}
+
+static gint
+run_netconfig (GError **error)
+{
+       GPtrArray *argv;
+       gint stdin_fd;
+
+       argv = g_ptr_array_new ();
+       g_ptr_array_add (argv, "/sbin/netconfig");
+       g_ptr_array_add (argv, "modify");
+       g_ptr_array_add (argv, "--service");
+       g_ptr_array_add (argv, "NetworkManager");
+       g_ptr_array_add (argv, NULL);
+
+       if (!g_spawn_async_with_pipes (NULL, (char **) argv->pdata, NULL,
+                                                        G_SPAWN_DO_NOT_REAP_CHILD,
+                                                        netconfig_child_setup,
+                                                        NULL, NULL, &stdin_fd,
+                                                        NULL, NULL, error)) {
+               stdin_fd = -1;
+       }
+
+       g_ptr_array_free (argv, TRUE);
+
+       return stdin_fd;
+}
+
+static void
+write_to_netconfig (gint fd, const char *key, const char *value)
+{
+       char *str;
+       int x;
+
+       str = g_strdup_printf ("%s='%s'\n", key, value);
+       x = write (fd, str, strlen (str));
+       g_free (str);
+}
+
 static gboolean
-rewrite_resolv_conf (NMNamedManager *mgr, GError **error)
+update_resolv_conf (const char *iface,
+                               const char *domain,
+                               char **searches,
+                               char **nameservers,
+                               GError **error)
 {
-       NMNamedManagerPrivate *priv;
-       const char *tmp_resolv_conf = RESOLV_CONF ".tmp";
-       char *searches = NULL, *domain = NULL;
-       char *nameservers = NULL;
-       guint32 num_domains, num_searches, i;
-       NMIP4Config *composite;
-       GSList *iter;
-       FILE *f;
-       GString *str;
+       gint fd;
+       char *str;
 
-       g_return_val_if_fail (error != NULL, FALSE);
-       g_return_val_if_fail (*error == NULL, FALSE);
+       fd = run_netconfig (error);
+       if (fd < 0)
+               return FALSE;
 
-       priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
+       write_to_netconfig (fd, "INTERFACE", iface);
 
-       /* If the sysadmin disabled modifying resolv.conf, exit silently */
-       if (!nm_system_should_modify_resolv_conf ()) {
-               nm_info ("DHCP returned name servers but system has disabled dynamic modification!");
-               return TRUE;
+       if (searches) {
+               str = g_strjoinv (" ", searches);
+               write_to_netconfig (fd, "DNSDOMAIN", str);
+               g_free (str);
        }
 
+       if (nameservers) {
+               str = g_strjoinv (" ", nameservers);
+               write_to_netconfig (fd, "DNSSERVERS", str);
+               g_free (str);
+       }
+
+       close (fd);
+
+       return TRUE;
+}
+
+#else
+/**********************************/
+/* Generic */
+
+static gboolean
+update_resolv_conf (const char *iface,
+                               const char *domain,
+                               char **searches,
+                               char **nameservers,
+                               GError **error)
+{
+       const char *tmp_resolv_conf = RESOLV_CONF ".tmp";
+       char *domain_str = NULL;
+       char *searches_str = NULL;
+       char *nameservers_str = NULL;
+       FILE *f;
+
        if ((f = fopen (tmp_resolv_conf, "w")) == NULL) {
                g_set_error (error,
-                            NM_NAMED_MANAGER_ERROR,
-                            NM_NAMED_MANAGER_ERROR_SYSTEM,
-                            "Could not open " RESOLV_CONF ": %s\n",
-                            g_strerror (errno));
+                                  NM_NAMED_MANAGER_ERROR,
+                                  NM_NAMED_MANAGER_ERROR_SYSTEM,
+                                  "Could not open " RESOLV_CONF ": %s\n",
+                                  g_strerror (errno));
                return FALSE;
        }
 
        if (fprintf (f, "%s","# generated by NetworkManager, do not edit!\n\n") < 0) {
                g_set_error (error,
-                            NM_NAMED_MANAGER_ERROR,
-                            NM_NAMED_MANAGER_ERROR_SYSTEM,
-                            "Could not write " RESOLV_CONF ": %s\n",
-                            g_strerror (errno));
+                                  NM_NAMED_MANAGER_ERROR,
+                                  NM_NAMED_MANAGER_ERROR_SYSTEM,
+                                  "Could not write " RESOLV_CONF ": %s\n",
+                                  g_strerror (errno));
                fclose (f);
                return FALSE;
        }
 
+       if (domain)
+               domain_str = g_strconcat ("domain ", domain, "\n\n", NULL);
+
+       if (searches) {
+               char *tmp_str;
+
+               tmp_str = g_strjoinv (" ", searches);
+               searches_str = g_strconcat ("search ", tmp_str, "\n\n", NULL);
+               g_free (tmp_str);
+       }
+
+       if (nameservers) {
+               GString *str;
+               int num;
+               int i;
+
+               str = g_string_new ("");
+               num = g_strv_length (nameservers);
+
+               for (i = 0; i < num; i++) {
+                       if (i == 3) {
+                               g_string_append (str, "\n# ");
+                               g_string_append (str, _("NOTE: the glibc resolver does not support more than 3 nameservers."));
+                               g_string_append (str, "\n# ");
+                               g_string_append (str, _("The nameservers listed below may not be recognized."));
+                               g_string_append_c (str, '\n');
+                       }
+
+                       g_string_append (str, "nameserver ");
+                       g_string_append (str, nameservers[i]);
+                       g_string_append_c (str, '\n');
+               }
+
+               nameservers_str = g_string_free (str, FALSE);
+       }
+
+       if (fprintf (f, "%s%s%s\n",
+                    domain ? domain : "",
+                    searches_str ? searches_str : "",
+                    nameservers_str ? nameservers_str : "") < 0) {
+               g_set_error (error,
+                                  NM_NAMED_MANAGER_ERROR,
+                                  NM_NAMED_MANAGER_ERROR_SYSTEM,
+                                  "Could not write to " RESOLV_CONF ": %s\n",
+                                  g_strerror (errno));
+       }
+
+       g_free (domain_str);
+       g_free (searches_str);
+       g_free (nameservers_str);
+
+       if (fclose (f) < 0) {
+               if (*error == NULL) {
+                       g_set_error (error,
+                                          NM_NAMED_MANAGER_ERROR,
+                                          NM_NAMED_MANAGER_ERROR_SYSTEM,
+                                          "Could not close " RESOLV_CONF ": %s\n",
+                                          g_strerror (errno));
+               }
+       }
+
+       if (*error == NULL) {
+               if (rename (tmp_resolv_conf, RESOLV_CONF) < 0) {
+                       g_set_error (error,
+                                          NM_NAMED_MANAGER_ERROR,
+                                          NM_NAMED_MANAGER_ERROR_SYSTEM,
+                                          "Could not replace " RESOLV_CONF ": %s\n",
+                                          g_strerror (errno));
+               }
+       }
+
+       return *error ? FALSE : TRUE;
+}
+#endif
+
+#define ADDR_BUF_LEN 50
+
+static gboolean
+rewrite_resolv_conf (NMNamedManager *mgr, const char *iface, GError **error)
+{
+       NMNamedManagerPrivate *priv;
+       NMIP4Config *composite;
+       GSList *iter;
+       GPtrArray *array;
+       const char *domain = NULL;
+       char **searches = NULL;
+       char **nameservers = NULL;
+       int num_domains;
+       int num_searches;
+       int num_nameservers;
+       int i;
+       gboolean success;
+
+       g_return_val_if_fail (error != NULL, FALSE);
+       g_return_val_if_fail (*error == NULL, FALSE);
+
+       priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
+
        /* Construct the composite config from all the currently active IP4Configs */
        composite = nm_ip4_config_new ();
 
@@ -239,79 +371,65 @@ rewrite_resolv_conf (NMNamedManager *mgr, GError **error)
        num_domains = nm_ip4_config_get_num_domains (composite);
        num_searches = nm_ip4_config_get_num_searches (composite);
 
+       /* Domain */
+       if (num_domains > 0)
+               domain = nm_ip4_config_get_domain (composite, 0);
+
+       /* Searches */
        if ((num_searches == 0)  && (num_domains > 0)) {
-               str = g_string_new ("search");
-               for (i = 0; i < num_domains; i++) {
-                       g_string_append_c (str, ' ');
-                       g_string_append (str, nm_ip4_config_get_domain (composite, i));         
-               }
+               array = g_ptr_array_sized_new (num_domains + 1);
+               for (i = 0; i < num_domains; i++)
+                       g_ptr_array_add (array, g_strdup (nm_ip4_config_get_domain (composite, i)));
 
-               g_string_append (str, "\n\n");
-               searches = g_string_free (str, FALSE);
+               g_ptr_array_add (array, NULL);
+               searches = (char **) g_ptr_array_free (array, FALSE);
        } else if (num_searches > 0) {
-               str = g_string_new ("search");
-               for (i = 0; i < num_searches; i++) {
-                       g_string_append_c (str, ' ');
-                       g_string_append (str, nm_ip4_config_get_search (composite, i));         
-               }
+               array = g_ptr_array_sized_new (num_searches + 1);
+               for (i = 0; i < num_searches; i++)
+                       g_ptr_array_add (array, g_strdup (nm_ip4_config_get_search (composite, i)));
 
-               g_string_append (str, "\n\n");
-               searches = g_string_free (str, FALSE);
+               g_ptr_array_add (array, NULL);
+               searches = (char **) g_ptr_array_free (array, FALSE);
        }
 
-       /* Compute resolv.conf domain */
-       if (num_domains > 0) {
-               str = g_string_new ("domain ");
-               g_string_append (str, nm_ip4_config_get_domain (composite, 0));
-               g_string_append (str, "\n\n");
+       /* Name servers */
+       num_nameservers = nm_ip4_config_get_num_nameservers (composite);
+       if (num_nameservers > 0) {
+               array = g_ptr_array_sized_new (num_nameservers + 1);
+               for (i = 0; i < num_nameservers; i++) {
+                       struct in_addr addr;
+                       char *buf;
+
+                       addr.s_addr = nm_ip4_config_get_nameserver (composite, i);
+                       buf = g_malloc0 (ADDR_BUF_LEN);
+                       if (!buf)
+                               continue;
+
+                       if (inet_ntop (AF_INET, &addr, buf, ADDR_BUF_LEN))
+                               g_ptr_array_add (array, buf);
+                       else
+                               nm_warning ("%s: error converting IP4 address 0x%X",
+                                                 __func__, ntohl (addr.s_addr));
+               }
 
-               domain = g_string_free (str, FALSE);
+               g_ptr_array_add (array, NULL);
+               nameservers = (char **) g_ptr_array_free (array, FALSE);
        }
 
-       /* Using glibc resolver */
-       nameservers = compute_nameservers (composite);
-       if (fprintf (f, "%s%s%s\n",
-                    domain ? domain : "",
-                    searches ? searches : "",
-                    nameservers ? nameservers : "") < 0) {
-               g_set_error (error,
-                            NM_NAMED_MANAGER_ERROR,
-                            NM_NAMED_MANAGER_ERROR_SYSTEM,
-                            "Could not write to " RESOLV_CONF ": %s\n",
-                            g_strerror (errno));
-       }
-       g_free (nameservers);
-
-       if (fclose (f) < 0) {
-               if (*error == NULL) {
-                       g_set_error (error,
-                                    NM_NAMED_MANAGER_ERROR,
-                                    NM_NAMED_MANAGER_ERROR_SYSTEM,
-                                    "Could not close " RESOLV_CONF ": %s\n",
-                                    g_strerror (errno));
-               }
-       }
+       success = update_resolv_conf (iface, domain, searches, nameservers, error);
 
-       g_free (domain);
-       g_free (searches);
+       g_strfreev (searches);
+       g_strfreev (nameservers);
 
-       if (*error == NULL) {
-               if (rename (tmp_resolv_conf, RESOLV_CONF) < 0) {
-                       g_set_error (error,
-                                    NM_NAMED_MANAGER_ERROR,
-                                    NM_NAMED_MANAGER_ERROR_SYSTEM,
-                                    "Could not replace " RESOLV_CONF ": %s\n",
-                                    g_strerror (errno));
-               } else {
-                       nm_system_update_dns ();
-               }
-       }
+       if (success)
+               nm_system_update_dns ();
 
-       return *error ? FALSE : TRUE;
+       return success;
 }
 
 gboolean
 nm_named_manager_add_ip4_config (NMNamedManager *mgr,
+                                                  const char *iface,
                                  NMIP4Config *config,
                                  NMNamedIPConfigType cfg_type)
 {
@@ -319,6 +437,7 @@ nm_named_manager_add_ip4_config (NMNamedManager *mgr,
        GError *error = NULL;
 
        g_return_val_if_fail (mgr != NULL, FALSE);
+       g_return_val_if_fail (iface != NULL, FALSE);
        g_return_val_if_fail (config != NULL, FALSE);
 
        priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
@@ -338,7 +457,7 @@ nm_named_manager_add_ip4_config (NMNamedManager *mgr,
        if (!g_slist_find (priv->configs, config))
                priv->configs = g_slist_append (priv->configs, g_object_ref (config));
 
-       if (!rewrite_resolv_conf (mgr, &error)) {
+       if (!rewrite_resolv_conf (mgr, iface, &error)) {
                nm_warning ("Could not commit DNS changes.  Error: '%s'", error ? error->message : "(none)");
                g_error_free (error);
        }
@@ -347,12 +466,15 @@ nm_named_manager_add_ip4_config (NMNamedManager *mgr,
 }
 
 gboolean
-nm_named_manager_remove_ip4_config (NMNamedManager *mgr, NMIP4Config *config)
+nm_named_manager_remove_ip4_config (NMNamedManager *mgr,
+                                                        const char *iface,
+                                                        NMIP4Config *config)
 {
        NMNamedManagerPrivate *priv;
        GError *error = NULL;
 
        g_return_val_if_fail (mgr != NULL, FALSE);
+       g_return_val_if_fail (iface != NULL, FALSE);
        g_return_val_if_fail (config != NULL, FALSE);
 
        priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
@@ -371,7 +493,7 @@ nm_named_manager_remove_ip4_config (NMNamedManager *mgr, NMIP4Config *config)
 
        g_object_unref (config);        
 
-       if (!rewrite_resolv_conf (mgr, &error)) {
+       if (!rewrite_resolv_conf (mgr, iface, &error)) {
                nm_warning ("Could not commit DNS changes.  Error: '%s'", error ? error->message : "(none)");
                if (error)
                        g_error_free (error);
index 33f4dec..00787a8 100644 (file)
@@ -68,10 +68,13 @@ GType nm_named_manager_get_type (void);
 NMNamedManager * nm_named_manager_get (void);
 
 gboolean nm_named_manager_add_ip4_config (NMNamedManager *mgr,
+                                         const char *iface,
                                           NMIP4Config *config,
                                           NMNamedIPConfigType cfg_type);
 
-gboolean nm_named_manager_remove_ip4_config (NMNamedManager *mgr, NMIP4Config *config);
+gboolean nm_named_manager_remove_ip4_config (NMNamedManager *mgr,
+                                            const char *iface,
+                                            NMIP4Config *config);
 
 G_END_DECLS
 
index 9b20649..070b556 100644 (file)
@@ -1734,13 +1734,14 @@ nm_device_set_ip4_config (NMDevice *self, NMIP4Config *config, NMDeviceStateReas
        g_return_val_if_fail (reason != NULL, FALSE);
 
        priv = NM_DEVICE_GET_PRIVATE (self);
+       ip_iface = nm_device_get_ip_iface (self);
 
        if (priv->ip4_config) {
                NMNamedManager *named_mgr;
 
                /* Remove any previous IP4 Config from the named manager */
                named_mgr = nm_named_manager_get ();
-               nm_named_manager_remove_ip4_config (named_mgr, priv->ip4_config);
+               nm_named_manager_remove_ip4_config (named_mgr, ip_iface, priv->ip4_config);
                g_object_unref (named_mgr);
 
                g_object_unref (priv->ip4_config);
@@ -1752,8 +1753,6 @@ nm_device_set_ip4_config (NMDevice *self, NMIP4Config *config, NMDeviceStateReas
 
        priv->ip4_config = g_object_ref (config);
 
-       ip_iface = nm_device_get_ip_iface (self);
-
        success = nm_system_device_set_from_ip4_config (ip_iface, config);
        if (success) {
                nm_device_update_ip4_address (self);