clean shutdown on SIGTERM (NetBSD, 3.0.1rc10)

Greg Troxel gdt at ir.bbn.com
Fri Jan 2 15:40:22 UTC 2004


On NetBSD 1.6.1 (with 3.0.1rc10), I found that shutting down dhclient
with SIGTERM did not release the lease and unconfigure the interface
etc.

The following patch causes dhclient to shut down cleanly on SIGTERM,
much as if it were requested to do so via OMAPI :-)

I realize that there may be concerns about signals and portability.

    Greg Troxel


patch -p2 for your tree, probably - this is against NetBSD sources.

Index: dist/dhcp/client/dhclient.c
===================================================================
RCS file: /QUIST-CVS/netbsd/src/dist/dhcp/client/dhclient.c,v
retrieving revision 1.1.1.4
retrieving revision 1.3
diff -u -r1.1.1.4 -r1.3
--- dist/dhcp/client/dhclient.c	2 Dec 2003 15:14:22 -0000	1.1.1.4
+++ dist/dhcp/client/dhclient.c	2 Dec 2003 17:20:39 -0000	1.3
@@ -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)
@@ -272,6 +273,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,


More information about the dhcp-hackers mailing list