tree-wide: s/sigprocmask/pthread_sigmask()/g

The behavior of sigprocmask() is unspecified in multi-threaded programs. Let's use pthread_sigmask() instead. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent db69009d
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <libgen.h> #include <libgen.h>
#include <pthread.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -263,7 +264,7 @@ int main(int argc, char *argv[]) ...@@ -263,7 +264,7 @@ int main(int argc, char *argv[])
if (ret < 0) if (ret < 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
ret = sigprocmask(SIG_SETMASK, &mask, &omask); ret = pthread_sigmask(SIG_SETMASK, &mask, &omask);
if (ret < 0) if (ret < 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -337,7 +338,7 @@ int main(int argc, char *argv[]) ...@@ -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) { if (ret < 0) {
SYSERROR("Failed to set signal mask"); SYSERROR("Failed to set signal mask");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -365,7 +366,7 @@ int main(int argc, char *argv[]) ...@@ -365,7 +366,7 @@ int main(int argc, char *argv[])
if (ret < 0) if (ret < 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
ret = sigprocmask(SIG_SETMASK, &omask, NULL); ret = pthread_sigmask(SIG_SETMASK, &omask, NULL);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to set signal mask"); SYSERROR("Failed to set signal mask");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -385,7 +386,7 @@ int main(int argc, char *argv[]) ...@@ -385,7 +386,7 @@ int main(int argc, char *argv[])
sigdelset(&mask, SIGSEGV) || sigdelset(&mask, SIGSEGV) ||
sigdelset(&mask, SIGBUS) || sigdelset(&mask, SIGBUS) ||
sigdelset(&mask, SIGTERM) || sigdelset(&mask, SIGTERM) ||
sigprocmask(SIG_BLOCK, &mask, NULL)) { pthread_sigmask(SIG_BLOCK, &mask, NULL)) {
SYSERROR("Failed to set signal mask."); SYSERROR("Failed to set signal mask.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <grp.h> #include <grp.h>
#include <poll.h> #include <poll.h>
#include <pthread.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -281,7 +282,7 @@ static int setup_signal_fd(sigset_t *oldmask) ...@@ -281,7 +282,7 @@ static int setup_signal_fd(sigset_t *oldmask)
return -EBADF; return -EBADF;
} }
ret = sigprocmask(SIG_BLOCK, &mask, oldmask); ret = pthread_sigmask(SIG_BLOCK, &mask, oldmask);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to set signal mask"); SYSERROR("Failed to set signal mask");
return -EBADF; return -EBADF;
...@@ -831,7 +832,7 @@ int lxc_init(const char *name, struct lxc_handler *handler) ...@@ -831,7 +832,7 @@ int lxc_init(const char *name, struct lxc_handler *handler)
return 0; return 0;
out_restore_sigmask: out_restore_sigmask:
sigprocmask(SIG_SETMASK, &handler->oldmask, NULL); pthread_sigmask(SIG_SETMASK, &handler->oldmask, NULL);
out_delete_tty: out_delete_tty:
lxc_delete_tty(&conf->tty_info); lxc_delete_tty(&conf->tty_info);
out_aborting: out_aborting:
...@@ -844,7 +845,7 @@ out_close_maincmd_fd: ...@@ -844,7 +845,7 @@ out_close_maincmd_fd:
void lxc_fini(const char *name, struct lxc_handler *handler) void lxc_fini(const char *name, struct lxc_handler *handler)
{ {
int i, rc; int i, ret;
struct lxc_list *cur, *next; struct lxc_list *cur, *next;
pid_t self = lxc_raw_getpid(); pid_t self = lxc_raw_getpid();
char *namespaces[LXC_NS_MAX + 1]; char *namespaces[LXC_NS_MAX + 1];
...@@ -857,9 +858,9 @@ void lxc_fini(const char *name, struct lxc_handler *handler) ...@@ -857,9 +858,9 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
for (i = 0; i < LXC_NS_MAX; i++) { for (i = 0; i < LXC_NS_MAX; i++) {
if (handler->nsfd[i] != -1) { 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]); ns_info[i].proc_name, self, handler->nsfd[i]);
if (rc == -1) { if (ret == -1) {
SYSERROR("Failed to allocate memory."); SYSERROR("Failed to allocate memory.");
break; break;
} }
...@@ -926,8 +927,9 @@ void lxc_fini(const char *name, struct lxc_handler *handler) ...@@ -926,8 +927,9 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
} }
/* Reset mask set by setup_signal_fd. */ /* Reset mask set by setup_signal_fd. */
if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL)) ret = pthread_sigmask(SIG_SETMASK, &handler->oldmask, NULL);
WARN("Failed to restore signal mask."); if (ret < 0)
WARN("%s - Failed to restore signal mask", strerror(errno));
lxc_console_delete(&handler->conf->console); lxc_console_delete(&handler->conf->console);
lxc_delete_tty(&handler->conf->tty_info); lxc_delete_tty(&handler->conf->tty_info);
...@@ -1093,7 +1095,7 @@ static int do_start(void *data) ...@@ -1093,7 +1095,7 @@ static int do_start(void *data)
goto out_warn_father; goto out_warn_father;
} }
ret = sigprocmask(SIG_SETMASK, &handler->oldmask, NULL); ret = pthread_sigmask(SIG_SETMASK, &handler->oldmask, NULL);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to set signal mask"); SYSERROR("Failed to set signal mask");
goto out_warn_father; goto out_warn_father;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <grp.h> #include <grp.h>
#include <inttypes.h> #include <inttypes.h>
#include <libgen.h> #include <libgen.h>
#include <pthread.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -495,7 +496,7 @@ struct lxc_popen_FILE *lxc_popen(const char *command) ...@@ -495,7 +496,7 @@ struct lxc_popen_FILE *lxc_popen(const char *command)
if (ret < 0) if (ret < 0)
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
ret = sigprocmask(SIG_UNBLOCK, &mask, NULL); ret = pthread_sigmask(SIG_UNBLOCK, &mask, NULL);
if (ret < 0) if (ret < 0)
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment