Move the actual work when dhclient got signal out of signal handlers,
and make not to exit the program if the signal is hanldled properly. Reviewed by: Ted Lemon
This commit is contained in:
parent
8ee940971e
commit
9ce05a481a
@ -113,6 +113,9 @@ available but BOOTP is. In that case, it may be advantageous to
|
||||
arrange with the network administrator for an entry on the BOOTP
|
||||
database, so that the host can boot quickly on that network rather
|
||||
than cycling through the list of old leases.
|
||||
.PP
|
||||
If dhclient receives the signal SIGHUP, it re-initialize the leases.
|
||||
On receipt of the signal SIGTERM, it release the leases, then exits.
|
||||
.SH COMMAND LINE
|
||||
.PP
|
||||
The names of the network interfaces that dhclient should attempt to
|
||||
|
@ -56,7 +56,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static char ocopyright[] =
|
||||
"$Id: dhclient.c,v 1.22 1999/04/26 15:47:03 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
|
||||
"$Id: dhclient.c,v 1.23 1999/08/24 03:25:31 enami Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "dhcpd.h"
|
||||
@ -88,9 +88,10 @@ u_int16_t remote_port;
|
||||
int log_priority;
|
||||
int no_daemon;
|
||||
int save_scripts;
|
||||
int caught_signal;
|
||||
|
||||
void catch_sighup PROTO ((int));
|
||||
void catch_sigterm PROTO ((int));
|
||||
void catch_signal PROTO ((int));
|
||||
int error_handler PROTO ((void));
|
||||
|
||||
static char copyright[] =
|
||||
"Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.";
|
||||
@ -211,11 +212,11 @@ int main (argc, argv, envp)
|
||||
(void) sigaddset (&sa.sa_mask, SIGHUP);
|
||||
(void) sigaddset (&sa.sa_mask, SIGTERM);
|
||||
|
||||
sa.sa_handler = catch_sighup;
|
||||
sa.sa_handler = catch_signal;
|
||||
if (sigaction (SIGHUP, &sa, NULL))
|
||||
error ("Unable to setup SIGHUP handler.");
|
||||
|
||||
sa.sa_handler = catch_sigterm;
|
||||
sa.sa_handler = catch_signal;
|
||||
if (sigaction (SIGTERM, &sa, NULL))
|
||||
error ("Unable to setup SIGTERM handler.");
|
||||
|
||||
@ -295,7 +296,7 @@ int main (argc, argv, envp)
|
||||
sysconf_startup (status_message);
|
||||
|
||||
/* Start dispatching packets and timeouts... */
|
||||
dispatch ();
|
||||
dispatch (error_handler);
|
||||
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
@ -2224,24 +2225,49 @@ void status_message (header, data)
|
||||
error ("Unable to restore signals in sysconf handler.");
|
||||
}
|
||||
|
||||
void catch_sighup (sig)
|
||||
void catch_signal (sig)
|
||||
int sig;
|
||||
{
|
||||
|
||||
/* Treat this like NETWORK_LOCATION_CHANGED; re-initiialize
|
||||
the leases. */
|
||||
client_reinit (1);
|
||||
caught_signal = sig;
|
||||
}
|
||||
|
||||
void catch_sigterm (sig)
|
||||
int sig;
|
||||
/* handle select(2) or poll(2) error. */
|
||||
int error_handler ()
|
||||
{
|
||||
int sig;
|
||||
|
||||
/* Treat this like RELEASE_CURRENT_DHCP_LEASES; release
|
||||
leases. Then exit. */
|
||||
client_reinit (0);
|
||||
cleanup();
|
||||
exit (0);
|
||||
switch (errno) {
|
||||
case EINTR:
|
||||
#ifdef USE_POLL
|
||||
case EAGAIN:
|
||||
#endif
|
||||
sig = caught_signal;
|
||||
caught_signal = 0;
|
||||
switch (sig) {
|
||||
case SIGHUP:
|
||||
/* Treat this like NETWORK_LOCATION_CHANGED;
|
||||
re-initiialize the leases. */
|
||||
client_reinit (1);
|
||||
return 0;
|
||||
|
||||
case SIGTERM:
|
||||
/* Treat this like RELEASE_CURRENT_DHCP_LEASES; release
|
||||
leases. Then exit. */
|
||||
client_reinit (0);
|
||||
cleanup();
|
||||
exit (0);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void client_reinit (state)
|
||||
|
@ -42,11 +42,14 @@
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"$Id: dispatch.c,v 1.1.1.11 1999/03/29 23:00:51 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
|
||||
"$Id: dispatch.c,v 1.2 1999/08/24 03:25:32 enami Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "dhcpd.h"
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef USE_POLL
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
struct interface_info *interfaces, *dummy_interfaces, *fallback_interface;
|
||||
struct protocol *protocols;
|
||||
@ -530,7 +533,8 @@ void reinitialize_interfaces ()
|
||||
addressing information from it, and then call through the
|
||||
bootp_packet_handler hook to try to do something with it. */
|
||||
|
||||
void dispatch ()
|
||||
void dispatch (error_handler)
|
||||
int (*error_handler) PROTO((void));
|
||||
{
|
||||
struct protocol *l;
|
||||
int nfds = 0;
|
||||
@ -538,6 +542,7 @@ void dispatch ()
|
||||
int count;
|
||||
int i;
|
||||
int to_msec;
|
||||
int saved_errno;
|
||||
|
||||
nfds = 0;
|
||||
for (l = protocols; l; l = l -> next) {
|
||||
@ -593,10 +598,12 @@ void dispatch ()
|
||||
|
||||
/* Not likely to be transitory... */
|
||||
if (count < 0) {
|
||||
if (errno == EAGAIN || errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
saved_errno = errno;
|
||||
if (error_handler == NULL || (*error_handler) ()) {
|
||||
errno = saved_errno;
|
||||
error ("poll: %m");
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
@ -619,12 +626,14 @@ void dispatch ()
|
||||
addressing information from it, and then call through the
|
||||
bootp_packet_handler hook to try to do something with it. */
|
||||
|
||||
void dispatch ()
|
||||
void dispatch (error_handler)
|
||||
int (*error_handler) PROTO((void));
|
||||
{
|
||||
fd_set r, w, x;
|
||||
struct protocol *l;
|
||||
int max = 0;
|
||||
int count;
|
||||
int saved_errno;
|
||||
struct timeval tv, *tvp;
|
||||
|
||||
FD_ZERO (&w);
|
||||
@ -667,8 +676,14 @@ void dispatch ()
|
||||
GET_TIME (&cur_time);
|
||||
|
||||
/* Not likely to be transitory... */
|
||||
if (count < 0)
|
||||
error ("select: %m");
|
||||
if (count < 0) {
|
||||
saved_errno = errno;
|
||||
if (error_handler == NULL || (*error_handler) ()) {
|
||||
errno = saved_errno;
|
||||
error ("select: %m");
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
|
||||
for (l = protocols; l; l = l -> next) {
|
||||
if (!FD_ISSET (l -> fd, &r))
|
||||
|
@ -808,7 +808,7 @@ extern struct timeout *timeouts;
|
||||
void discover_interfaces PROTO ((int));
|
||||
struct interface_info *setup_fallback PROTO ((void));
|
||||
void reinitialize_interfaces PROTO ((void));
|
||||
void dispatch PROTO ((void));
|
||||
void dispatch PROTO ((int (*) PROTO ((void))));
|
||||
int locate_network PROTO ((struct packet *));
|
||||
void got_one PROTO ((struct protocol *));
|
||||
void add_timeout PROTO ((TIME, void (*) PROTO ((void *)), void *));
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static char ocopyright [] =
|
||||
"$Id: dhcrelay.c,v 1.1.1.14 1999/04/26 15:43:10 mellon Exp $ Copyright (c) 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
|
||||
"$Id: dhcrelay.c,v 1.2 1999/08/24 03:25:32 enami Exp $ Copyright (c) 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "dhcpd.h"
|
||||
@ -248,7 +248,7 @@ int main (argc, argv, envp)
|
||||
}
|
||||
|
||||
/* Start dispatching packets and timeouts... */
|
||||
dispatch ();
|
||||
dispatch (NULL);
|
||||
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static char ocopyright[] =
|
||||
"$Id: dhcpd.c,v 1.13 1999/04/26 15:47:04 mellon Exp $ Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.";
|
||||
"$Id: dhcpd.c,v 1.14 1999/08/24 03:25:33 enami Exp $ Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.";
|
||||
#endif
|
||||
|
||||
static char copyright[] =
|
||||
@ -288,7 +288,7 @@ int main (argc, argv, envp)
|
||||
bootp_packet_handler = do_packet;
|
||||
|
||||
/* Receive packets and dispatch them... */
|
||||
dispatch ();
|
||||
dispatch (NULL);
|
||||
|
||||
/* Not reached */
|
||||
return 0;
|
||||
|
@ -44,7 +44,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"$Id: sysconfd.c,v 1.2 1999/02/18 22:14:01 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
|
||||
"$Id: sysconfd.c,v 1.3 1999/08/24 03:25:33 enami Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "dhcpd.h"
|
||||
@ -124,7 +124,7 @@ int main (argc, argv, envp)
|
||||
/* Kernel status stuff goes here... */
|
||||
|
||||
/* Wait for something to happen... */
|
||||
dispatch ();
|
||||
dispatch (NULL);
|
||||
|
||||
exit (0);
|
||||
}
|
||||
@ -253,5 +253,3 @@ void dhcp (packet)
|
||||
struct packet *packet;
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user