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

Bug#109455: dbootstrap thinks dhcp succeeds even when there's no IP



Hi,

The way I read this is that we should be able to make dhclient exit with an
error if it can't configure the interface.  With that in mind I wrote the
included patch. I tested this on my system and it works like I want it to.

I verified that currently dhclient will exit with success if it can't
configure the interface, presumably it wants to try again later.  That
is no good for boot-floppies, we want to know _now_ whether it worked
or not.

With this patch if you pass '-e' to dhclient it will exit non-zero if it fails
to get the interface, i.e.:

Oct 24 17:20:44 oink dhclient-2.2.x: DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 9
Oct 24 17:20:53 oink dhclient-2.2.x: No DHCPOFFERS received.
Oct 24 17:20:53 oink dhclient-2.2.x: No working leases in persistent database. 
Oct 24 17:20:53 oink dhclient-2.2.x: Exiting. 

I suggest we reassign this bug to dhclient, then NMU if necessary.
Many users will use dhcp, it is silly if they don't know right away
whether or not the interface was configured properly.


-David

diff -u dhcp-2.0pl5/client/dhclient.c dhcp-2.0pl5/client/dhclient.c
--- dhcp-2.0pl5/client/dhclient.c
+++ dhcp-2.0pl5/client/dhclient.c
@@ -89,6 +89,7 @@
 int log_priority;
 int no_daemon;
 int save_scripts;
+int exit_on_panic = 0;
 
 static char copyright[] =
 "Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.";
@@ -166,6 +167,8 @@
 		} else if (!strcmp (argv [i], "-q")) {
 			quiet = 1;
 			quiet_interface_discovery = 1;
+		} else if (!strcmp (argv [i], "-e")) {
+			exit_on_panic = 1;
  		} else if (argv [i][0] == '-') {
  		    usage (s);
  		} else {
@@ -312,7 +315,7 @@
 	note (url);
 	note ("");
 
-	warn ("Usage: %s [-c] [-d] [-p <port>] [-lf lease-file]", appname);
+	warn ("Usage: %s [-c] [-d] [-e] [-p <port>] [-lf lease-file]", appname);
 	error ("       [-pf pidfile] [interface]");
 }
 
@@ -1114,7 +1117,11 @@
 /* state_panic gets called if we haven't received any offers in a preset
    amount of time.   When this happens, we try to use existing leases that
    haven't yet expired, and failing that, we call the client script and
-   hope it can do something. */
+   hope it can do something. 
+   
+   Unless we've been told at the command line to exit on panic in which case
+   we do our best to get an interface and then exit with an error if we can't.
+   */
 
 void state_panic (ipp)
 	void *ipp;
@@ -1200,8 +1207,11 @@
 
 	/* No leases were available, or what was available didn't work, so
 	   tell the shell script that we failed to allocate an address,
-	   and try again later. */
-	note ("No working leases in persistent database - sleeping.\n");
+	   and try again later. 
+	   
+	   Unless we've been told to exit on an error, in which case we 
+	   do just that. */
+	note ("No working leases in persistent database.\n");
 	script_init (ip, "FAIL", (struct string_list *)0);
 	if (ip -> client -> alias)
 		script_write_params (ip, "alias_", ip -> client -> alias);
@@ -1209,6 +1219,13 @@
 	ip -> client -> state = S_INIT;
 	add_timeout (cur_time + ip -> client -> config -> retry_interval,
 		     state_init, ip);
+	
+	if (exit_on_panic) {
+	    note ("Exiting.\n");
+	    exit(1);
+	}
+
+	note ("Sleeping.\n");
 	go_daemon ();
 }
 
diff -u dhcp-2.0pl5/debian/changelog dhcp-2.0pl5/debian/changelog
--- dhcp-2.0pl5/debian/changelog
+++ dhcp-2.0pl5/debian/changelog
@@ -1,3 +1,10 @@
+dhcp (2.0pl5-6.2) unstable; urgency=low
+
+  * add an option so the client will exit with an error if 
+    it fails to configure an interface. (closes: #109455) 
+
+ -- David Kimdon <dwhedon@debian.org>  Wed, 24 Oct 2001 15:55:54 -0700
+
 dhcp (2.0pl5-6.1) unstable; urgency=high
 
   * NMU to fix RC bugs; specifically the urgency is high for
only in patch2:
--- dhcp-2.0pl5.orig/client/dhclient.8
+++ dhcp-2.0pl5/client/dhclient.8
@@ -45,6 +45,9 @@
 .I port
 ]
 [
+.B -e
+]
+[
 .B -d
 ]
 [
@@ -141,6 +144,12 @@
 flag should be specified.  This is useful when running dhclient under
 a debugger, or when running it out of inittab on System V systems.
 .PP
+The
+.B -e
+flag will cause dhclient to exit with an error if the interface cannot 
+be configured after a certain amount of time. This is useful when dhclient
+is used in scripts or other systems when a failed dhcp attempt needs to be
+reported.
 .SH CONFIGURATION
 The syntax of the dhclient.conf(8) file is discussed seperately.
 .SH FILES




Reply to: