Skip to content

Commit

Permalink
tree-wide: s/sigprocmask/pthread_sigmask()/g
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christian Brauner committed May 24, 2018
1 parent 73b5b70 commit b467714
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/lxc/cmd/lxc_init.c
Expand Up @@ -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>
Expand Down Expand Up @@ -266,7 +267,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);

Expand Down Expand Up @@ -340,7 +341,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);
Expand Down Expand Up @@ -368,7 +369,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);
Expand Down
3 changes: 2 additions & 1 deletion src/lxc/cmd/lxc_monitord.c
Expand Up @@ -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>
Expand Down Expand Up @@ -386,7 +387,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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/lxc/start.c
Expand Up @@ -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>
Expand Down Expand Up @@ -314,7 +315,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;
Expand Down Expand Up @@ -860,7 +861,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->ttys);
out_aborting:
Expand Down Expand Up @@ -986,7 +987,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
}

/* Reset mask set by setup_signal_fd. */
ret = sigprocmask(SIG_SETMASK, &handler->oldmask, NULL);
ret = pthread_sigmask(SIG_SETMASK, &handler->oldmask, NULL);
if (ret < 0)
WARN("%s - Failed to restore signal mask", strerror(errno));

Expand Down Expand Up @@ -1064,7 +1065,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;
Expand Down
7 changes: 4 additions & 3 deletions src/lxc/terminal.c
Expand Up @@ -24,6 +24,7 @@
#include <errno.h>
#include <fcntl.h>
#include <lxc/lxccontainer.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -172,7 +173,7 @@ struct lxc_terminal_state *lxc_terminal_signal_init(int srcfd, int dstfd)
goto on_error;
}

ret = sigprocmask(SIG_BLOCK, &mask, &ts->oldmask);
ret = pthread_sigmask(SIG_BLOCK, &mask, &ts->oldmask);
if (ret < 0) {
WARN("Failed to block signals");
goto on_error;
Expand All @@ -181,7 +182,7 @@ struct lxc_terminal_state *lxc_terminal_signal_init(int srcfd, int dstfd)
ts->sigfd = signalfd(-1, &mask, SFD_CLOEXEC);
if (ts->sigfd < 0) {
WARN("Failed to create signal fd");
sigprocmask(SIG_SETMASK, &ts->oldmask, NULL);
(void)pthread_sigmask(SIG_SETMASK, &ts->oldmask, NULL);
goto on_error;
}

Expand All @@ -206,7 +207,7 @@ void lxc_terminal_signal_fini(struct lxc_terminal_state *ts)
if (ts->sigfd >= 0) {
close(ts->sigfd);

if (sigprocmask(SIG_SETMASK, &ts->oldmask, NULL) < 0)
if (pthread_sigmask(SIG_SETMASK, &ts->oldmask, NULL) < 0)
WARN("%s - Failed to restore signal mask", strerror(errno));
}

Expand Down
3 changes: 2 additions & 1 deletion src/lxc/utils.c
Expand Up @@ -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>
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit b467714

Please sign in to comment.