Subject: Re: Clean shutdown of services in /etc/rc.d
To: =?iso-8859-1?q?Gr=E9goire_Sutre?= <sutre@labri.fr>
From: Greg Troxel <gdt@ir.bbn.com>
List: tech-userlevel
Date: 11/07/2003 09:38:04
It seems to me that the underlying problem is that dhclient doesn't
clean up after itself when shut down in the normal, default case
(SIGTERM).  To me, this should include not only restoring resolv.conf
(which I don't personally care about), but also deleting the address
that it assigned, and, if it brought the interface up in the first
place, taking it down.

I would guess (without having looked) that this has been flamed about
extensively in dhcp implementation land, so this may be easier done
than accepted.

It took only a little longer to do than say, though: dhclient is set
up to do the right thing on command from a control socket, but does
not seem to catch signals.

Arguably this should be optional (or rather, not doing it should be
optional).


Index: dist/dhcp/client/dhclient.c
===================================================================
RCS file: /QUIST-CVS/netbsd/src/dist/dhcp/client/dhclient.c,v
retrieving revision 1.1.1.3
retrieving revision 1.2
diff -u -r1.1.1.3 -r1.2
--- dist/dhcp/client/dhclient.c	3 Apr 2002 03:32:50 -0000	1.1.1.3
+++ dist/dhcp/client/dhclient.c	7 Nov 2003 14:35:27 -0000	1.2
@@ -87,6 +87,7 @@
 
 static void usage PROTO ((void));
 
+static void catch_sigterm(int x);
 void do_release(struct client_state *);
 
 int main (argc, argv, envp)
@@ -273,6 +274,9 @@
 	} else
 		log_perror = 0;
 
+	/* Set up SIGTERM handler to clean up state. */
+	signal(SIGTERM, &catch_sigterm);
+
 	/* If we're given a relay agent address to insert, for testing
 	   purposes, figure out what it is. */
 	if (relay) {
@@ -2931,6 +2935,12 @@
 static void shutdown_exit (void *foo)
 {
 	exit (0);
+}
+
+static void catch_sigterm(int x)
+{
+	/* undo resolv.conf, release leases, unconfigure interface */
+	dhcp_set_control_state(0 /* XXX unused */, server_shutdown);
 }
 
 isc_result_t dhcp_set_control_state (control_object_state_t oldstate,



-- 
        Greg Troxel <gdt@ir.bbn.com>