From: Roy Marples Date: Wed, 7 Nov 2007 10:15:14 +0000 (+0000) Subject: Clear the signal_pipe fd from the fdset when all signals have X-Git-Tag: v3.2.3~168 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de8a9d9887e862c9fefc9b6ff3520c572a57b924;p=thirdparty%2Fdhcpcd.git Clear the signal_pipe fd from the fdset when all signals have been read. --- diff --git a/ChangeLog b/ChangeLog index b933aff2..1c092e24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +Clear the signal_pipe fd from the fdset when all signals have +been read. Don't release a link local address. Use sysconf to detect if we have a working monotonic clock. Only request NTP, NIS, etc if we have compiled that feature in. diff --git a/arp.c b/arp.c index 72574d02..e42781cc 100644 --- a/arp.c +++ b/arp.c @@ -143,7 +143,7 @@ int arp_claim (interface_t *iface, struct in_addr address) maxfd = signal_fd_set (&rset, iface->fd); if ((s = select (maxfd + 1, &rset, NULL, NULL, &tv)) == -1) { if (errno == EINTR) { - if (signal_read (NULL) == -1) { + if (signal_exists (NULL) == -1) { errno = 0; continue; } else diff --git a/client.c b/client.c index fededbcc..4c3c7409 100644 --- a/client.c +++ b/client.c @@ -432,7 +432,7 @@ int dhcp_run (const options_t *options, int *pidfd) retval = 0; /* We should always handle our signals first */ - if ((sig = (signal_read (NULL))) != -1) + if ((sig = (signal_read (&rset))) != -1) { switch (sig) { case SIGINT: @@ -446,7 +446,6 @@ int dhcp_run (const options_t *options, int *pidfd) goto eexit; case SIGALRM: - logger (LOG_INFO, "received SIGALRM, renewing lease"); switch (state) { case STATE_BOUND: diff --git a/signals.c b/signals.c index 214a6247..bb36cf6c 100644 --- a/signals.c +++ b/signals.c @@ -84,22 +84,39 @@ int signal_fd_set (fd_set *rfds, int extra_fd) return signal_pipe[0] > extra_fd ? signal_pipe[0] : extra_fd; } +/* Check if we have a signal or not */ +int signal_exists (const fd_set *rfds) +{ + if (signal_signal || (rfds && FD_ISSET (signal_pipe[0], rfds))) + return 0; + return -1; +} + /* Read a signal from the signal pipe. Returns 0 if there is * no signal, -1 on error (and sets errno appropriately), and * your signal on success */ -int signal_read (const fd_set *rfds) +int signal_read (fd_set *rfds) { - int sig; + int sig = -1; + + if (signal_signal) { + sig = signal_signal; + signal_signal = 0; + } + + if (rfds && FD_ISSET (signal_pipe[0], rfds)) { + int buflen = sizeof (sig) * 2; + char buf[buflen]; + size_t bytes; - if (signal_signal) - return signal_signal; + memset (buf, 0, buflen); + bytes = read (signal_pipe[0], buf, buflen); - if (! rfds || ! FD_ISSET (signal_pipe[0], rfds)) - return -1; - - if (read (signal_pipe[0], &sig, sizeof (sig)) == -1) - return -1; + /* We need to clear us from rfds if nothing left in the buffer + * in case we are called many times */ + if (bytes == sizeof (sig)) + FD_CLR (signal_pipe[0], rfds); + } return sig; } - diff --git a/signals.h b/signals.h index 1accb6cd..b043dbf9 100644 --- a/signals.h +++ b/signals.h @@ -22,6 +22,7 @@ void signal_setup (void); int signal_fd_set (fd_set *rfds, int extra_fd); -int signal_read (const fd_set *rfds); +int signal_exists (const fd_set *rfds); +int signal_read (fd_set *rfds); #endif