Subject: bin/23949: dhclient fails to release leases when sent SIGTERM
To: None <gnats-bugs@gnats.netbsd.org>
From: None <gdt@ir.bbn.com>
List: netbsd-bugs
Date: 01/02/2004 10:29:25
>Number:         23949
>Category:       bin
>Synopsis:       dhclient fails to release leases when sent SIGTERM
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 02 15:30:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Greg Troxel
>Release:        NetBSD 1.6.1_STABLE
>Organization:
        Greg Troxel <gdt@ir.bbn.com>
>Environment:
	
	
System: NetBSD fnord.ir.bbn.com 1.6.1_STABLE NetBSD 1.6.1_STABLE (FNORD) #7: Mon Oct 6 15:46:22 EDT 2003 root@fnord.ir.bbn.com:/home/gdt/QUIST-current/netbsd/src/sys/arch/i386/compile/FNORD i386
Architecture: i386
Machine: i386
>Description:
dhclient does not release leases when sent SIGTERM.
It does have code to clean up (release lease with server, unconfigure
address, restore resolv.conf, etc., which is invoked if it is shut
down via OMAPI).

>How-To-Repeat:

Run dhclient.  'pkill dhclient'.  Observe that the server did not get
a DHCPRELEASE, and that the interface is still configured.

>Fix:

Call the cleanup code when catching a signal.

I have been running with this for over a month with no observed ill effects.

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,

>Release-Note:
>Audit-Trail:
>Unformatted: