[patch] Support Debian's resolvconf



I've been playing with NetworkManager on my laptop (running Ubuntu).
I'm rather pleased with it in general, but I use the resolvconf [1]
package for managing /etc/resolv.conf. NetworkManager's named-manager
currently fights with resolvconf by moving a new file on top of
/etc/resolv.conf, which resolvconf expects it to be a symlink to
/etc/resolvconf/run/resolv.conf (which it generates from other files).

The attached patch tests for the existence (and executablity) of
/sbin/resolvconf, and uses it to manage libc resolver info if it is
there. If /sbin/resolvconf is not executable, behaviour should be
unchanged.

I'm not sure exactly what the effect would be in the NO_NAMED case. If
I've overlooked something, I'd be happy to rework the patch.

[1] http://linux.com.hk/PenguinWeb/manpage.jsp?section=8&name=resolvconf

-- 
Will Dyson
Index: src/named-manager/nm-named-manager.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/named-manager/nm-named-manager.c,v
retrieving revision 1.1
diff -u -r1.1 nm-named-manager.c
--- src/named-manager/nm-named-manager.c	15 Apr 2005 15:43:41 -0000	1.1
+++ src/named-manager/nm-named-manager.c	28 Jul 2005 15:28:42 -0000
@@ -46,6 +46,14 @@
 #define RESOLV_CONF "/etc/resolv.conf"
 #endif
 
+#ifndef RESOLVCONF_IFACE
+#define RESOLVCONF_IFACE "lo.nm-named"
+#endif
+
+#ifndef RESOLVCONF_BIN
+#define RESOLVCONF_BIN "/sbin/resolvconf"
+#endif
+
 /* From NetworkManagerSystem.h/.c */
 void nm_system_update_dns (void);
 
@@ -70,6 +78,8 @@
 					   GValue *value,
 					   GParamSpec *pspec);
 static gboolean rewrite_resolv_conf (NMNamedManager *mgr, GError **error);
+static gboolean set_resolv_conf (NMNamedManager *mgr, GError **error);
+static gboolean unset_resolv_conf (NMNamedManager *mgr, GError **error);
 
 struct NMNamedManagerPrivate
 {
@@ -182,7 +192,7 @@
 	 * resolv.conf isn't stuck pointing to 127.0.0.1.
 	 */
 	mgr->priv->use_named = FALSE;
-	rewrite_resolv_conf (mgr, NULL);
+	unset_resolv_conf (mgr, NULL);
 #endif
 
 	if (mgr->priv->named_conf)
@@ -313,7 +323,7 @@
 
 #ifdef NM_NO_NAMED
 	if (mgr->priv->use_named == FALSE)
-		return rewrite_resolv_conf (mgr, error);
+		return unset_resolv_conf (mgr, error);
 
 #else
 	int out_fd;
@@ -524,7 +534,7 @@
 	mgr->priv->child_watch = NULL;
 #endif
 
-	if (!rewrite_resolv_conf (mgr, error))
+	if (!set_resolv_conf (mgr, error))
 	{
 		kill (mgr->priv->named_pid, SIGTERM);
 		mgr->priv->named_pid = 0;
@@ -659,6 +669,51 @@
 	return FALSE;
 }
 
+static gboolean
+set_resolv_conf (NMNamedManager *mgr, GError **error)
+{
+	char *searches = NULL;
+	FILE *f;
+
+	if (!g_file_test (RESOLVCONF_BIN, G_FILE_TEST_IS_EXECUTABLE))
+		return rewrite_resolv_conf(mgr, error);
+
+	if ((f = popen (RESOLVCONF_BIN " -a " RESOLVCONF_IFACE, "w")) == NULL)
+		goto lose;
+	
+	searches = compute_domain_searches (mgr);
+
+	/* Using caching-nameserver & local DNS */
+	if (fprintf (f, "%s%s", searches, "\n\nnameserver 127.0.0.1\n") < 0) {
+		goto lose;
+	}
+	g_free (searches);
+	if (pclose (f) < 0)
+		goto lose;
+
+	nm_system_update_dns ();
+	return TRUE;
+
+ lose:
+	g_free (searches);
+	g_set_error (error,
+		     NM_NAMED_MANAGER_ERROR,
+		     NM_NAMED_MANAGER_ERROR_SYSTEM,
+		     "Could not run resolvconf: %s\n", g_strerror (errno));
+	return FALSE;
+}
+
+static gboolean
+unset_resolv_conf (NMNamedManager *mgr, GError **error)
+{
+	if (!g_file_test (RESOLVCONF_BIN, G_FILE_TEST_IS_EXECUTABLE))
+		return rewrite_resolv_conf(mgr, error);
+	
+	system (RESOLVCONF_BIN " -d " RESOLVCONF_IFACE);
+	return TRUE;
+}
+
+
 guint
 nm_named_manager_add_domain_search (NMNamedManager *mgr,
 				    const char *domain,
@@ -674,7 +729,7 @@
 	g_hash_table_insert (mgr->priv->domain_searches,
 			     GUINT_TO_POINTER (id),
 			     g_strdup (domain));
-	if (!rewrite_resolv_conf (mgr, error)) {
+	if (!set_resolv_conf (mgr, error)) {
 		g_hash_table_remove (mgr->priv->global_ipv4_nameservers,
 				     GUINT_TO_POINTER (id));
 		return 0;
@@ -696,7 +751,7 @@
 			     "Invalid domain search id");
 		return FALSE;
 	}
-	if (!rewrite_resolv_conf (mgr, error))
+	if (!set_resolv_conf (mgr, error))
 		return FALSE;
 	return TRUE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]