]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Replace usages of sigwait(3) with sigwaitinfo(2)
authorTobias Brunner <tobias@strongswan.org>
Thu, 17 Sep 2015 15:52:14 +0000 (17:52 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 29 Oct 2015 14:38:37 +0000 (15:38 +0100)
This is basically the same call, but it has the advantage of being
supported by FreeBSD's valgrind, which sigwait() is not.

References #1106.

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 6f2b6f1780f6f3919eb9752e44dd226b669bd8d2..b8f943f5185accd6fff8c360103d9cada13b57eb 100644 (file)
  */
 
 #include <stdio.h>
-#define _POSIX_PTHREAD_SEMANTICS /* for two param sigwait on OpenSolaris */
 #include <signal.h>
-#undef _POSIX_PTHREAD_SEMANTICS
 #include <pthread.h>
 #include <sys/types.h>
 #include <sys/utsname.h>
 #include <unistd.h>
 #include <getopt.h>
+#include <errno.h>
 
 #include <library.h>
 #include <hydra.h>
@@ -112,12 +111,11 @@ static int run()
        while (TRUE)
        {
                int sig;
-               int error;
 
-               error = sigwait(&set, &sig);
-               if (error)
+               sig = sigwaitinfo(&set, NULL);
+               if (sig == -1)
                {
-                       DBG1(DBG_DMN, "error %d while waiting for a signal", error);
+                       DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
                        return 1;
                }
                switch (sig)
@@ -382,7 +380,7 @@ int main(int argc, char *argv[])
        lib->plugins->status(lib->plugins, LEVEL_CTRL);
 
        /* add handler for SEGV and ILL,
-        * INT, TERM and HUP are handled by sigwait() in run() */
+        * INT, TERM and HUP are handled by sigwaitinfo() in run() */
        action.sa_handler = segv_handler;
        action.sa_flags = 0;
        sigemptyset(&action.sa_mask);
index 80551f8534a7a53be0ef9deca77700c014f0a5b9..1773e7c3987cf8cdef61f3e0c1a63632ef9540f7 100644 (file)
@@ -18,6 +18,7 @@
 #include <signal.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <hydra.h>
 #include <daemon.h>
@@ -80,12 +81,11 @@ static void run()
        while (TRUE)
        {
                int sig;
-               int error;
 
-               error = sigwait(&set, &sig);
-               if (error)
+               sig = sigwaitinfo(&set, NULL);
+               if (sig == -1)
                {
-                       DBG1(DBG_DMN, "error %d while waiting for a signal", error);
+                       DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
                        return;
                }
                switch (sig)
@@ -237,7 +237,7 @@ int main(int argc, char *argv[])
        }
 
        /* add handler for SEGV and ILL,
-        * INT and TERM are handled by sigwait() in run() */
+        * INT and TERM are handled by sigwaitinfo() in run() */
        action.sa_handler = segv_handler;
        action.sa_flags = 0;
        sigemptyset(&action.sa_mask);
index e391a539795c264fad282e7d55029a7d98e51224..5b43831a4c485541defcfc11b1c5f879781ae26c 100644 (file)
@@ -249,10 +249,10 @@ static int run()
 
        while (TRUE)
        {
-               int sig, error;
+               int sig;
 
-               error = sigwait(&set, &sig);
-               if (error)
+               sig = sigwaitinfo(&set, NULL);
+               if (sig == -1)
                {
                        DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(error));
                        return SS_RC_INITIALIZATION_FAILED;
@@ -393,7 +393,7 @@ int main(int argc, char *argv[])
        }
 
        /* add handler for SEGV and ILL,
-        * INT, TERM and HUP are handled by sigwait() in run() */
+        * INT, TERM and HUP are handled by sigwaitinfo() in run() */
        action.sa_handler = segv_handler;
        action.sa_flags = 0;
        sigemptyset(&action.sa_mask);
index 7c60f0ca80bacb68e9f6c098dbccda0d33dd89fd..2b278d58e99cfd97253e94de8b1983d427bb79c5 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <libgen.h>
+#include <errno.h>
 
 #include <hydra.h>
 #include <daemon.h>
@@ -98,12 +99,11 @@ static void run()
        while (TRUE)
        {
                int sig;
-               int error;
 
-               error = sigwait(&set, &sig);
-               if (error)
+               sig = sigwaitinfo(&set, NULL);
+               if (sig == -1)
                {
-                       DBG1(DBG_DMN, "error %d while waiting for a signal", error);
+                       DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(error));
                        return;
                }
                switch (sig)
@@ -358,7 +358,7 @@ int main(int argc, char *argv[])
        lib->encoding->add_encoder(lib->encoding, tkm_encoder_encode);
 
        /* add handler for SEGV and ILL,
-        * INT and TERM are handled by sigwait() in run() */
+        * INT and TERM are handled by sigwaitinfo() in run() */
        action.sa_handler = segv_handler;
        action.sa_flags = 0;
        sigemptyset(&action.sa_mask);
index 081e49490bfbd93bc8d1b4a12855827c77ad2d34..f03b6e1ba9410489d8cdf216c9596cdd4197690a 100644 (file)
@@ -17,9 +17,7 @@
  */
 
 #include <stdio.h>
-#define _POSIX_PTHREAD_SEMANTICS /* for two param sigwait on OpenSolaris */
 #include <signal.h>
-#undef _POSIX_PTHREAD_SEMANTICS
 #include <pthread.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -110,12 +108,11 @@ static void run()
        while (TRUE)
        {
                int sig;
-               int error;
 
-               error = sigwait(&set, &sig);
-               if (error)
+               sig = sigwaitinfo(&set, NULL);
+               if (sig == -1)
                {
-                       DBG1(DBG_DMN, "error %d while waiting for a signal", error);
+                       DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
                        return;
                }
                switch (sig)
@@ -434,7 +431,7 @@ int main(int argc, char *argv[])
        }
 
        /* add handler for SEGV and ILL,
-        * INT, TERM and HUP are handled by sigwait() in run() */
+        * INT, TERM and HUP are handled by sigwaitinfo() in run() */
        action.sa_handler = segv_handler;
        action.sa_flags = 0;
        sigemptyset(&action.sa_mask);
index 584a2698a17982a721165220d02738e366562d83..a134d5352b0d1e01728e4665865dda6df9ef8bac 100644 (file)
@@ -563,7 +563,7 @@ int main(int argc, char *argv[])
        sigaddset(&set, SIGTERM);
        sigprocmask(SIG_BLOCK, &set, NULL);
 
-       while (sigwait(&set, &sig) == 0)
+       while ((sig = sigwaitinfo(&set, NULL)) != -1)
        {
                switch (sig)
                {
index 2393c2790bec3aeebdefc80fd2d50cedecb885b1..5b8f98e2510a4b9b24361dd4838ba1cd87454534 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <signal.h>
 #include <pthread.h>
+#include <errno.h>
 
 #include <library.h>
 #include <hydra.h>
@@ -84,9 +85,10 @@ static int run()
        {
                int sig;
 
-               if (sigwait(&set, &sig))
+               sig = sigwaitinfo(&set, NULL);
+               if (sig == -1)
                {
-                       DBG1(DBG_DMN, "error while waiting for a signal");
+                       DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
                        return 1;
                }
                switch (sig)
@@ -206,7 +208,7 @@ int main(int argc, char *argv[])
                 VERSION, utsname.sysname, utsname.release, utsname.machine);
 
        /* add handler for SEGV and ILL,
-        * INT, TERM and HUP are handled by sigwait() in run() */
+        * INT, TERM and HUP are handled by sigwaitinfo() in run() */
        action.sa_handler = segv_handler;
        action.sa_flags = 0;
        sigemptyset(&action.sa_mask);
index 4daf91905bf04eb2a4b14be340ce379a7d664ad0..b4c6ce3a6d0d94e36116c1a31bbdc7876f00029a 100644 (file)
@@ -383,14 +383,13 @@ METHOD(fast_dispatcher_t, waitsignal, void,
        private_fast_dispatcher_t *this)
 {
        sigset_t set;
-       int sig;
 
        sigemptyset(&set);
        sigaddset(&set, SIGINT);
        sigaddset(&set, SIGTERM);
        sigaddset(&set, SIGHUP);
        sigprocmask(SIG_BLOCK, &set, NULL);
-       sigwait(&set, &sig);
+       sigwaitinfo(&set, NULL);
 }
 
 METHOD(fast_dispatcher_t, destroy, void,
index b4a4db802441b75bee4cf5eafd6e65dbb1ba0234..fca614ef4a25448ae6f26cd290fe335bc5f20dff 100644 (file)
@@ -117,14 +117,13 @@ void wait_sigint()
 void wait_sigint()
 {
        sigset_t set;
-       int sig;
 
        sigemptyset(&set);
        sigaddset(&set, SIGINT);
        sigaddset(&set, SIGTERM);
 
        sigprocmask(SIG_BLOCK, &set, NULL);
-       sigwait(&set, &sig);
+       sigwaitinfo(&set, NULL);
 }
 
 #endif