[PATCH] Detect dhclient version, support dhclient 3 in NM 0.8.1



Hi,

I wrote the attached patch to support detecting at build-time the
version of dhclient being available. This allows disabling the new
arguments that isc-dhcp 4 expects and thus allow 0.8.1 to work with
dhclient v3.

-- 
Mathieu Trudel-Lapierre - mathieu trudel-lapierre canonical com
Freenode: cyphermox, Jabber: mathieu tl gmail com
4096R/EE018C93 1967 8F7D 03A1 8F38 732E  FF82 C126 33E1 EE01 8C93

diff --git a/configure.ac b/configure.ac
index e1b9347..13bc5b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -319,7 +319,8 @@ case "${with_dhclient}" in
 		for path in /sbin /usr/sbin /usr/pkg/sbin /usr/local/sbin; do
 			test -x "${path}/dhclient" || continue
 			case `"$path/dhclient" --version 2>&1` in
-				"isc-dhclient-4"*) DHCLIENT_PATH="$path/dhclient"; break;;
+				"isc-dhclient-4"*) DHCLIENT_PATH="$path/dhclient"; DHCLIENT_VERSION=4; break;;
+				"isc-dhclient-V3"*) DHCLIENT_PATH="$path/dhclient"; DHCLIENT_VERSION=3; break;;
 			esac
 		done
 		if test -n "${DHCLIENT_PATH}"; then
@@ -327,6 +328,10 @@ case "${with_dhclient}" in
 		else
 			AC_MSG_RESULT(no)
 		fi
+		if test -n "${DHCLIENT_VERSION}"; then
+			AC_MSG_NOTICE(Found dhclient version ${DHCLIENT_VERSION}.)
+			AC_SUBST(DHCLIENT_VERSION)
+		fi
 		;;
 esac
 
diff --git a/src/dhcp-manager/Makefile.am b/src/dhcp-manager/Makefile.am
index f75e6b3..4c54087 100644
--- a/src/dhcp-manager/Makefile.am
+++ b/src/dhcp-manager/Makefile.am
@@ -29,6 +29,7 @@ libdhcp_manager_la_CPPFLAGS = \
 	-DLIBEXECDIR=\"$(libexecdir)\" \
 	-DLOCALSTATEDIR=\"$(localstatedir)\" \
 	-DDHCLIENT_PATH=\"$(DHCLIENT_PATH)\" \
+	-DDHCLIENT_V$(DHCLIENT_VERSION) \
 	-DDHCPCD_PATH=\"$(DHCPCD_PATH)\"
 
 libdhcp_manager_la_LIBADD = \
diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c
index cae7df2..0007946 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient.c
+++ b/src/dhcp-manager/nm-dhcp-dhclient.c
@@ -45,7 +45,11 @@ G_DEFINE_TYPE (NMDHCPDhclient, nm_dhcp_dhclient, NM_TYPE_DHCP_CLIENT)
 #define NM_DHCP_DHCLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_DHCLIENT, NMDHCPDhclientPrivate))
 
 #if defined(TARGET_DEBIAN) || defined(TARGET_SUSE) || defined(TARGET_MANDRIVA)
+#if defined(DHCLIENT_V3)
+#define NM_DHCLIENT_LEASE_DIR		LOCALSTATEDIR "/lib/dhcp3"
+#else
 #define NM_DHCLIENT_LEASE_DIR           LOCALSTATEDIR "/lib/dhcp"
+#endif
 #else
 #define NM_DHCLIENT_LEASE_DIR           LOCALSTATEDIR "/lib/dhclient"
 #endif
@@ -437,7 +441,11 @@ create_dhclient_config (const char *iface,
 #if defined(TARGET_SUSE)
 	orig = g_strdup (SYSCONFDIR "/dhclient.conf");
 #elif defined(TARGET_DEBIAN) || defined(TARGET_GENTOO)
+#if defined(DHCLIENT_V3)
+	orig = g_strdup (SYSCONFDIR "/dhcp3/dhclient.conf");
+#else
 	orig = g_strdup (SYSCONFDIR "/dhcp/dhclient.conf");
+#endif
 #else
 	orig = g_strdup_printf (SYSCONFDIR "/dhclient-%s.conf", iface);
 #endif
@@ -499,7 +507,6 @@ dhclient_start (NMDHCPClient *client,
 	guint log_domain;
 
 	g_return_val_if_fail (priv->pid_file == NULL, -1);
-	g_return_val_if_fail (ip_opt != NULL, -1);
 
 	iface = nm_dhcp_client_get_iface (client);
 	uuid = nm_dhcp_client_get_uuid (client);
@@ -536,10 +543,13 @@ dhclient_start (NMDHCPClient *client,
 
 	g_ptr_array_add (argv, (gpointer) "-d");
 
+#if !defined(DHCLIENT_V3)
+	g_return_val_if_fail (ip_opt != NULL, -1);
 	g_ptr_array_add (argv, (gpointer) ip_opt);
 
 	if (mode_opt)
 		g_ptr_array_add (argv, (gpointer) mode_opt);
+#endif
 
 	g_ptr_array_add (argv, (gpointer) "-sf");	/* Set script file */
 	g_ptr_array_add (argv, (gpointer) ACTION_SCRIPT_PATH );

Attachment: signature.asc
Description: This is a digitally signed message part



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