]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Clear the signal_pipe fd from the fdset when all signals have
authorRoy Marples <roy@marples.name>
Wed, 7 Nov 2007 10:15:14 +0000 (10:15 +0000)
committerRoy Marples <roy@marples.name>
Wed, 7 Nov 2007 10:15:14 +0000 (10:15 +0000)
been read.

ChangeLog
arp.c
client.c
signals.c
signals.h

index b933aff2315d71a1040e75a65c26fbbeab1124c5..1c092e245fdd738fbe5b6108c5422e3a604242d7 100644 (file)
--- 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 72574d02134646ebf50c020f821d219cfe812e5e..e42781cc6e69d2dd1a82ca8f531fd515bc6818f3 100644 (file)
--- 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
index fededbcc7917078696a7f987da77f033e6d39aba..4c3c7409171af229eabed09e2ab10329b4a6020f 100644 (file)
--- 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:
index 214a62471e35d265de0d8a79b6e8ea9504a33116..bb36cf6c2c12bae9993dd425c29e2cc66e991161 100644 (file)
--- 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;
 }
-
index 1accb6cd15acce086f49ddacf7166279cf75c3de..b043dbf929656e6b986ff0179692ff27d908f1b9 100644 (file)
--- 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