]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tree-wide: s/sigprocmask/pthread_sigmask()/g
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 24 May 2018 18:29:48 +0000 (20:29 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 10 Dec 2018 07:29:59 +0000 (08:29 +0100)
The behavior of sigprocmask() is unspecified in multi-threaded programs. Let's
use pthread_sigmask() instead.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxc_init.c
src/lxc/lxc_monitord.c
src/lxc/start.c
src/lxc/utils.c

index d42247e2f5f7a1f8973823a9c4c49704a1028fbd..ddba38da6ff173006cff9307d7904e6bb3a4fd41 100644 (file)
@@ -25,6 +25,7 @@
 #include <errno.h>
 #include <getopt.h>
 #include <libgen.h>
+#include <pthread.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -263,7 +264,7 @@ int main(int argc, char *argv[])
        if (ret < 0)
                exit(EXIT_FAILURE);
 
-       ret = sigprocmask(SIG_SETMASK, &mask, &omask);
+       ret = pthread_sigmask(SIG_SETMASK, &mask, &omask);
        if (ret < 0)
                exit(EXIT_FAILURE);
 
@@ -337,7 +338,7 @@ int main(int argc, char *argv[])
                        }
                }
 
-               ret = sigprocmask(SIG_SETMASK, &omask, NULL);
+               ret = pthread_sigmask(SIG_SETMASK, &omask, NULL);
                if (ret < 0) {
                        SYSERROR("Failed to set signal mask");
                        exit(EXIT_FAILURE);
@@ -365,7 +366,7 @@ int main(int argc, char *argv[])
        if (ret < 0)
                exit(EXIT_FAILURE);
 
-       ret = sigprocmask(SIG_SETMASK, &omask, NULL);
+       ret = pthread_sigmask(SIG_SETMASK, &omask, NULL);
        if (ret < 0) {
                SYSERROR("Failed to set signal mask");
                exit(EXIT_FAILURE);
index ea292d000e9143e85a01aeddff835d7b12ad6207..e7e692a0cd11121830db597bcb0ecb0307440708 100644 (file)
@@ -24,6 +24,7 @@
 #define _GNU_SOURCE
 #include <errno.h>
 #include <fcntl.h>
+#include <pthread.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -385,7 +386,7 @@ int main(int argc, char *argv[])
            sigdelset(&mask, SIGSEGV) ||
            sigdelset(&mask, SIGBUS)  ||
            sigdelset(&mask, SIGTERM) ||
-           sigprocmask(SIG_BLOCK, &mask, NULL)) {
+           pthread_sigmask(SIG_BLOCK, &mask, NULL)) {
                SYSERROR("Failed to set signal mask.");
                exit(EXIT_FAILURE);
        }
index 593b67e2551303e6380e83de3f46cad4f409d552..dd335abf75916633592f66eeb7f4f3a1180d2dd7 100644 (file)
@@ -32,6 +32,7 @@
 #include <fcntl.h>
 #include <grp.h>
 #include <poll.h>
+#include <pthread.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -281,7 +282,7 @@ static int setup_signal_fd(sigset_t *oldmask)
                        return -EBADF;
        }
 
-       ret = sigprocmask(SIG_BLOCK, &mask, oldmask);
+       ret = pthread_sigmask(SIG_BLOCK, &mask, oldmask);
        if (ret < 0) {
                SYSERROR("Failed to set signal mask");
                return -EBADF;
@@ -831,7 +832,7 @@ int lxc_init(const char *name, struct lxc_handler *handler)
        return 0;
 
 out_restore_sigmask:
-       sigprocmask(SIG_SETMASK, &handler->oldmask, NULL);
+       pthread_sigmask(SIG_SETMASK, &handler->oldmask, NULL);
 out_delete_tty:
        lxc_delete_tty(&conf->tty_info);
 out_aborting:
@@ -844,7 +845,7 @@ out_close_maincmd_fd:
 
 void lxc_fini(const char *name, struct lxc_handler *handler)
 {
-       int i, rc;
+       int i, ret;
        struct lxc_list *cur, *next;
        pid_t self = lxc_raw_getpid();
        char *namespaces[LXC_NS_MAX + 1];
@@ -857,9 +858,9 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
 
        for (i = 0; i < LXC_NS_MAX; i++) {
                if (handler->nsfd[i] != -1) {
-                       rc = asprintf(&namespaces[namespace_count], "%s:/proc/%d/fd/%d",
+                       ret = asprintf(&namespaces[namespace_count], "%s:/proc/%d/fd/%d",
                                      ns_info[i].proc_name, self, handler->nsfd[i]);
-                       if (rc == -1) {
+                       if (ret == -1) {
                                SYSERROR("Failed to allocate memory.");
                                break;
                        }
@@ -926,8 +927,9 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
        }
 
        /* Reset mask set by setup_signal_fd. */
-       if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL))
-               WARN("Failed to restore signal mask.");
+       ret = pthread_sigmask(SIG_SETMASK, &handler->oldmask, NULL);
+       if (ret < 0)
+               WARN("%s - Failed to restore signal mask", strerror(errno));
 
        lxc_console_delete(&handler->conf->console);
        lxc_delete_tty(&handler->conf->tty_info);
@@ -1093,7 +1095,7 @@ static int do_start(void *data)
                goto out_warn_father;
        }
 
-       ret = sigprocmask(SIG_SETMASK, &handler->oldmask, NULL);
+       ret = pthread_sigmask(SIG_SETMASK, &handler->oldmask, NULL);
        if (ret < 0) {
                SYSERROR("Failed to set signal mask");
                goto out_warn_father;
index aa1676a01a96a17328f13b9feafd432029c3a528..665012e936fbc8d0e90fc2fcaeaa4152ab2b4578 100644 (file)
@@ -31,6 +31,7 @@
 #include <grp.h>
 #include <inttypes.h>
 #include <libgen.h>
+#include <pthread.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -495,7 +496,7 @@ struct lxc_popen_FILE *lxc_popen(const char *command)
                if (ret < 0)
                        _exit(EXIT_FAILURE);
 
-               ret = sigprocmask(SIG_UNBLOCK, &mask, NULL);
+               ret = pthread_sigmask(SIG_UNBLOCK, &mask, NULL);
                if (ret < 0)
                        _exit(EXIT_FAILURE);