sigwaitinfo() may fail with EINTR if interrupted by an unblocked signal not in the set
authorTobias Brunner <tobias@strongswan.org>
Thu, 19 Nov 2015 10:21:48 +0000 (11:21 +0100)
committerTobias Brunner <tobias@strongswan.org>
Mon, 23 Nov 2015 10:37:19 +0000 (11:37 +0100)
Fixes #1213.

src/charon-cmd/charon-cmd.c
src/charon-nm/charon-nm.c
src/charon-systemd/charon-systemd.c
src/charon-tkm/src/charon-tkm.c
src/charon/charon.c
src/conftest/conftest.c
src/frontends/osx/charon-xpc/charon-xpc.c
src/libfast/fast_dispatcher.c
src/libstrongswan/utils/utils.c

index b8f943f..d3b31cc 100644 (file)
@@ -115,6 +115,10 @@ static int run()
                sig = sigwaitinfo(&set, NULL);
                if (sig == -1)
                {
+                       if (errno == EINTR)
+                       {       /* ignore signals we didn't wait for */
+                               continue;
+                       }
                        DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
                        return 1;
                }
@@ -152,11 +156,6 @@ static int run()
                                charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
                                return 1;
                        }
-                       default:
-                       {
-                               DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
-                               break;
-                       }
                }
        }
 }
index 1773e7c..fb090e5 100644 (file)
@@ -85,6 +85,10 @@ static void run()
                sig = sigwaitinfo(&set, NULL);
                if (sig == -1)
                {
+                       if (errno == EINTR)
+                       {       /* ignore signals we didn't wait for */
+                               continue;
+                       }
                        DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
                        return;
                }
@@ -102,11 +106,6 @@ static void run()
                                charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
                                return;
                        }
-                       default:
-                       {
-                               DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
-                               break;
-                       }
                }
        }
 }
index f302d45..4286cde 100644 (file)
@@ -254,6 +254,10 @@ static int run()
                sig = sigwaitinfo(&set, NULL);
                if (sig == -1)
                {
+                       if (errno == EINTR)
+                       {       /* ignore signals we didn't wait for */
+                               continue;
+                       }
                        DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
                        return SS_RC_INITIALIZATION_FAILED;
                }
@@ -265,11 +269,6 @@ static int run()
                                charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
                                return 0;
                        }
-                       default:
-                       {
-                               DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
-                               break;
-                       }
                }
        }
 }
index 52d82f3..3923c8a 100644 (file)
@@ -104,6 +104,10 @@ static void run()
                sig = sigwaitinfo(&set, NULL);
                if (sig == -1)
                {
+                       if (errno == EINTR)
+                       {       /* ignore signals we didn't wait for */
+                               continue;
+                       }
                        DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
                        return;
                }
@@ -121,11 +125,6 @@ static void run()
                                charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
                                return;
                        }
-                       default:
-                       {
-                               DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
-                               break;
-                       }
                }
        }
 }
index f03b6e1..4c2a9a4 100644 (file)
@@ -98,7 +98,7 @@ static void run()
 {
        sigset_t set;
 
-       /* handle SIGINT, SIGHUP ans SIGTERM in this handler */
+       /* handle SIGINT, SIGHUP and SIGTERM in this handler */
        sigemptyset(&set);
        sigaddset(&set, SIGINT);
        sigaddset(&set, SIGHUP);
@@ -112,6 +112,10 @@ static void run()
                sig = sigwaitinfo(&set, NULL);
                if (sig == -1)
                {
+                       if (errno == EINTR)
+                       {       /* ignore signals we didn't wait for */
+                               continue;
+                       }
                        DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
                        return;
                }
@@ -144,11 +148,6 @@ static void run()
                                charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
                                return;
                        }
-                       default:
-                       {
-                               DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
-                               break;
-                       }
                }
        }
 }
index 9348b64..edfe0ca 100644 (file)
@@ -565,7 +565,7 @@ int main(int argc, char *argv[])
        sigaddset(&set, SIGTERM);
        sigprocmask(SIG_BLOCK, &set, NULL);
 
-       while ((sig = sigwaitinfo(&set, NULL)) != -1)
+       while ((sig = sigwaitinfo(&set, NULL)) != -1 || errno == EINTR)
        {
                switch (sig)
                {
index 5b8f98e..0d8f0f4 100644 (file)
@@ -88,6 +88,10 @@ static int run()
                sig = sigwaitinfo(&set, NULL);
                if (sig == -1)
                {
+                       if (errno == EINTR)
+                       {       /* ignore signals we didn't wait for */
+                               continue;
+                       }
                        DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
                        return 1;
                }
@@ -101,9 +105,6 @@ static int run()
                                DBG1(DBG_DMN, "signal of type SIGTERM received. Shutting down");
                                charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
                                return 0;
-                       default:
-                               DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
-                               break;
                }
        }
 }
index b4c6ce3..66a2ee5 100644 (file)
@@ -21,6 +21,7 @@
 #include <fcgiapp.h>
 #include <signal.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <utils/debug.h>
 #include <threading/thread.h>
@@ -389,7 +390,10 @@ METHOD(fast_dispatcher_t, waitsignal, void,
        sigaddset(&set, SIGTERM);
        sigaddset(&set, SIGHUP);
        sigprocmask(SIG_BLOCK, &set, NULL);
-       sigwaitinfo(&set, NULL);
+       while (sigwaitinfo(&set, NULL) == -1 && errno == EINTR)
+       {
+               /* wait for signal */
+       }
 }
 
 METHOD(fast_dispatcher_t, destroy, void,
index 4e86165..40cb43d 100644 (file)
@@ -124,7 +124,10 @@ void wait_sigint()
        sigaddset(&set, SIGTERM);
 
        sigprocmask(SIG_BLOCK, &set, NULL);
-       sigwaitinfo(&set, NULL);
+       while (sigwaitinfo(&set, NULL) == -1 && errno == EINTR)
+       {
+               /* wait for signal */
+       }
 }
 
 #ifndef HAVE_SIGWAITINFO