From: Christian Brauner Date: Thu, 24 May 2018 18:29:48 +0000 (+0200) Subject: tree-wide: s/sigprocmask/pthread_sigmask()/g X-Git-Tag: lxc-2.0.10~131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfd1d0176eba882d044573fa60f9b3e9521c38a2;p=thirdparty%2Flxc.git 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: Christian Brauner --- diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c index d42247e2f..ddba38da6 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/src/lxc/lxc_monitord.c b/src/lxc/lxc_monitord.c index ea292d000..e7e692a0c 100644 --- a/src/lxc/lxc_monitord.c +++ b/src/lxc/lxc_monitord.c @@ -24,6 +24,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -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); } diff --git a/src/lxc/start.c b/src/lxc/start.c index 593b67e25..dd335abf7 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/src/lxc/utils.c b/src/lxc/utils.c index aa1676a01..665012e93 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -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);