Subject: Re: Clean shutdown of services in /etc/rc.d
To: Greg Troxel <gdt@ir.bbn.com>
From: Luke Mewburn <lukem@NetBSD.org>
List: tech-userlevel
Date: 12/24/2003 17:35:10
--QQylggUiIGa0KLvv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Nov 07, 2003 at 09:38:04AM -0500, Greg Troxel wrote:
  | 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.

Have you passed this by Ted Lemon (mellon@NetBSD.org); the author of
ISC DHCP ?


  |=20
  | 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.
  |=20
  | 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.
  |=20
  | Arguably this should be optional (or rather, not doing it should be
  | optional).
  |=20
  |=20
  | Index: dist/dhcp/client/dhclient.c
  | =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
  | 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 @@
  | =20
  |  static void usage PROTO ((void));
  | =20
  | +static void catch_sigterm(int x);
  |  void do_release(struct client_state *);
  | =20
  |  int main (argc, argv, envp)
  | @@ -273,6 +274,9 @@
  |  	} else
  |  		log_perror =3D 0;
  | =20
  | +	/* 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);
  |  }
  | =20
  |  isc_result_t dhcp_set_control_state (control_object_state_t oldstate,
  |=20
  |=20
  |=20
  | --=20
  |         Greg Troxel <gdt@ir.bbn.com>

--QQylggUiIGa0KLvv
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (NetBSD)

iD8DBQE/6TOepBhtmn8zJHIRAgNQAKDYQzGisa+SQlCLBM/5qBZ97yJi2wCfSW7q
zfRNQdtFqGnSGSWfk+XBpVo=
=Ncm5
-----END PGP SIGNATURE-----

--QQylggUiIGa0KLvv--