From d1d199990cda8071a4b249f5589d9fef73da69c5 Mon Sep 17 00:00:00 2001
From: Tambet Ingo <tambet@gmail.com>
Date: Wed, 1 Apr 2009 10:02:52 +0300
Subject: [PATCH] Update resolv.conf once.


Index: NetworkManager-0.7.1/src/NetworkManagerPolicy.c
===================================================================
--- NetworkManager-0.7.1.orig/src/NetworkManagerPolicy.c
+++ NetworkManager-0.7.1/src/NetworkManagerPolicy.c
@@ -553,7 +553,7 @@ update_routing_and_dns (NMPolicy *policy
 	}
 
 	named_mgr = nm_named_manager_get ();
-	nm_named_manager_add_ip4_config (named_mgr, ip_iface, ip4_config, dns_type);
+	nm_named_manager_add_ip4_config (named_mgr, ip4_config, dns_type);
 	g_object_unref (named_mgr);
 
 	/* Now set new default active connection _after_ updating DNS info, so that
@@ -774,7 +774,10 @@ device_ip4_config_changed (NMDevice *dev
                            GParamSpec *pspec,
                            gpointer user_data)
 {
-	update_routing_and_dns ((NMPolicy *) user_data, TRUE);
+	if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED)
+		/* Update routing and DNS when the device is active and it's configuration changes.
+		   The device activation and deactivation are caught by device_state_changed() */
+		update_routing_and_dns ((NMPolicy *) user_data, TRUE);
 }
 
 static void
Index: NetworkManager-0.7.1/src/named-manager/nm-named-manager.c
===================================================================
--- NetworkManager-0.7.1.orig/src/named-manager/nm-named-manager.c
+++ NetworkManager-0.7.1/src/named-manager/nm-named-manager.c
@@ -183,7 +183,6 @@ static gboolean
 dispatch_netconfig (const char *domain,
                     char **searches,
                     char **nameservers,
-                    const char *iface,
                     const char *nis_domain,
                     const char *nis_servers,
                     GError **error)
@@ -197,8 +196,6 @@ dispatch_netconfig (const char *domain,
 	if (pid < 0)
 		return FALSE;
 
-	write_to_netconfig (fd, "INTERFACE", iface);
-
 	if (searches) {
 		str = g_strjoinv (" ", searches);
 
@@ -315,7 +312,6 @@ static gboolean
 dispatch_resolvconf (const char *domain,
                      char **searches,
                      char **nameservers,
-                     const char *iface,
                      GError **error)
 {
 	char *cmd;
@@ -327,7 +323,7 @@ dispatch_resolvconf (const char *domain,
 
 	if (domain || searches || nameservers) {
 		cmd = g_strconcat (RESOLVCONF_PATH, " -a ", "NetworkManager", NULL);
-		nm_info ("(%s): writing resolv.conf to %s", iface, RESOLVCONF_PATH);
+		nm_info ("writing resolv.conf to %s", RESOLVCONF_PATH);
 		if ((f = popen (cmd, "w")) == NULL)
 			g_set_error (error,
 				     NM_NAMED_MANAGER_ERROR,
@@ -341,7 +337,7 @@ dispatch_resolvconf (const char *domain,
 		}
 	} else {
 		cmd = g_strconcat (RESOLVCONF_PATH, " -d ", "NetworkManager", NULL);
-		nm_info ("(%s): removing resolv.conf from %s", iface, RESOLVCONF_PATH);
+		nm_info ("removing resolv.conf from %s", RESOLVCONF_PATH);
 		if (nm_spawn_process (cmd) == 0)
 			retval = TRUE;
 	}
@@ -356,7 +352,6 @@ static gboolean
 update_resolv_conf (const char *domain,
                     char **searches,
                     char **nameservers,
-                    const char *iface,
                     GError **error)
 {
 	const char *tmp_resolv_conf = RESOLV_CONF ".tmp";
@@ -442,7 +437,7 @@ compute_searches (guint32 num, NMIP4Conf
 }
 
 static gboolean
-rewrite_resolv_conf (NMNamedManager *mgr, const char *iface, GError **error)
+rewrite_resolv_conf (NMNamedManager *mgr, GError **error)
 {
 	NMNamedManagerPrivate *priv;
 	NMIP4Config *composite;
@@ -524,19 +519,22 @@ rewrite_resolv_conf (NMNamedManager *mgr
 	g_object_unref (composite);
 
 #ifdef RESOLVCONF_PATH
-	success = dispatch_resolvconf (domain, searches, nameservers, iface, error);
+	success = dispatch_resolvconf (domain, searches, nameservers, error);
 #endif
 
 #ifdef TARGET_SUSE
-	if (success == FALSE)
-		success = dispatch_netconfig (domain, searches, nameservers, iface,
-									  g_object_get_data (G_OBJECT (composite), "NISDOMAIN"),
-									  g_object_get_data (G_OBJECT (composite), "NISSERVERS"),
-									  error);
+	if (success == FALSE) {
+		/* On SUSE, never fall back to manual resolv.conf updating. */
+		success = TRUE;
+		dispatch_netconfig (domain, searches, nameservers,
+							g_object_get_data (G_OBJECT (composite), "NISDOMAIN"),
+							g_object_get_data (G_OBJECT (composite), "NISSERVERS"),
+							error);
+	}
 #endif
 
 	if (success == FALSE)
-		success = update_resolv_conf (domain, searches, nameservers, iface, error);
+		success = update_resolv_conf (domain, searches, nameservers, error);
 
 	if (success)
 		nm_system_update_dns ();
@@ -549,7 +547,6 @@ rewrite_resolv_conf (NMNamedManager *mgr
 
 gboolean
 nm_named_manager_add_ip4_config (NMNamedManager *mgr,
-						   const char *iface,
                                  NMIP4Config *config,
                                  NMNamedIPConfigType cfg_type)
 {
@@ -557,7 +554,6 @@ nm_named_manager_add_ip4_config (NMNamed
 	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);
@@ -577,7 +573,7 @@ nm_named_manager_add_ip4_config (NMNamed
 	if (!g_slist_find (priv->configs, config))
 		priv->configs = g_slist_append (priv->configs, g_object_ref (config));
 
-	if (!rewrite_resolv_conf (mgr, iface, &error)) {
+	if (!rewrite_resolv_conf (mgr, &error)) {
 		nm_warning ("Could not commit DNS changes.  Error: '%s'", error ? error->message : "(none)");
 		g_error_free (error);
 	}
@@ -587,14 +583,12 @@ nm_named_manager_add_ip4_config (NMNamed
 
 gboolean
 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);
@@ -613,7 +607,7 @@ nm_named_manager_remove_ip4_config (NMNa
 
 	g_object_unref (config);	
 
-	if (!rewrite_resolv_conf (mgr, iface, &error)) {
+	if (!rewrite_resolv_conf (mgr, &error)) {
 		nm_warning ("Could not commit DNS changes.  Error: '%s'", error ? error->message : "(none)");
 		if (error)
 			g_error_free (error);
Index: NetworkManager-0.7.1/src/named-manager/nm-named-manager.h
===================================================================
--- NetworkManager-0.7.1.orig/src/named-manager/nm-named-manager.h
+++ NetworkManager-0.7.1/src/named-manager/nm-named-manager.h
@@ -69,12 +69,10 @@ 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,
-					     const char *iface,
 					     NMIP4Config *config);
 
 G_END_DECLS
Index: NetworkManager-0.7.1/src/nm-device.c
===================================================================
--- NetworkManager-0.7.1.orig/src/nm-device.c
+++ NetworkManager-0.7.1/src/nm-device.c
@@ -1976,7 +1976,7 @@ nm_device_set_ip4_config (NMDevice *self
 	named_mgr = nm_named_manager_get ();
 	if (old_config) {
 		/* Remove any previous IP4 Config from the named manager */
-		nm_named_manager_remove_ip4_config (named_mgr, ip_iface, old_config);
+		nm_named_manager_remove_ip4_config (named_mgr, old_config);
 		g_object_unref (old_config);
 		priv->ip4_config = NULL;
 	}
@@ -1990,9 +1990,6 @@ nm_device_set_ip4_config (NMDevice *self
 			if (!nm_ip4_config_get_dbus_path (new_config))
 				nm_ip4_config_export (new_config);
 
-			/* Add the DNS information to the named manager */
-			nm_named_manager_add_ip4_config (named_mgr, ip_iface, new_config, NM_NAMED_IP_CONFIG_TYPE_DEFAULT);
-
 			nm_device_update_ip4_address (self);
 		}
 	}
Index: NetworkManager-0.7.1/src/vpn-manager/nm-vpn-connection.c
===================================================================
--- NetworkManager-0.7.1.orig/src/vpn-manager/nm-vpn-connection.c
+++ NetworkManager-0.7.1/src/vpn-manager/nm-vpn-connection.c
@@ -506,7 +506,7 @@ nm_vpn_connection_ip4_config_get (DBusGP
 
 		/* Add the VPN to DNS */
 		named_mgr = nm_named_manager_get ();
-		nm_named_manager_add_ip4_config (named_mgr, priv->tundev, config, NM_NAMED_IP_CONFIG_TYPE_VPN);
+		nm_named_manager_add_ip4_config (named_mgr, config, NM_NAMED_IP_CONFIG_TYPE_VPN);
 		g_object_unref (named_mgr);
 
 		priv->ip4_config = config;
@@ -943,7 +943,7 @@ vpn_cleanup (NMVPNConnection *connection
 
 		/* Remove attributes of the VPN's IP4 Config */
 		named_mgr = nm_named_manager_get ();
-		nm_named_manager_remove_ip4_config (named_mgr, priv->tundev, priv->ip4_config);
+		nm_named_manager_remove_ip4_config (named_mgr, priv->ip4_config);
 		g_object_unref (named_mgr);
 
 		/* Remove any previously added VPN gateway host route */
