From 50107cf2348804b199a90daff8a73d95121064d3 Mon Sep 17 00:00:00 2001 From: Andrey Saranchin <Andrey22102001@gmail.com> Date: Mon, 30 May 2022 03:55:13 +0300 Subject: [PATCH] replace sigprocmask() with pthread_sigmask() Since the use of sigprocmask() is unspecified in a multithreaded process we should use pthread_sigmask() instead. This patch replaces all the sigprocmask calls with pthread analogue. NO_TEST=refactoring NO_CHANGELOG=refactoring NO_DOC=refactoring --- src/lib/core/popen.c | 2 +- src/lib/core/say.c | 8 ++++---- src/main.cc | 4 ++-- third_party/coro/coro.c | 4 ++-- third_party/libev/ev.c | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c index e6026c22f4..41452d8b5e 100644 --- a/src/lib/core/popen.c +++ b/src/lib/core/popen.c @@ -993,7 +993,7 @@ signal_reset(void) /* Unblock any signals blocked by libev */ sigfillset(&sigset); - if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) == -1) { + if (pthread_sigmask(SIG_UNBLOCK, &sigset, NULL) == -1) { say_error("child: SIG_UNBLOCK failed"); _exit(errno); } diff --git a/src/lib/core/say.c b/src/lib/core/say.c index 378abb1fe7..69c826264b 100644 --- a/src/lib/core/say.c +++ b/src/lib/core/say.c @@ -381,8 +381,8 @@ log_pipe_init(struct log *log, const char *init_str) sigemptyset(&mask); sigaddset(&mask, SIGCHLD); - if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) - say_syserror("sigprocmask"); + if (pthread_sigmask(SIG_BLOCK, &mask, NULL) == -1) + say_syserror("pthread_sigmask"); if (pipe(pipefd) == -1) { diag_set(SystemError, "failed to create pipe"); @@ -401,7 +401,7 @@ log_pipe_init(struct log *log, const char *init_str) } if (log->pid == 0) { - sigprocmask(SIG_UNBLOCK, &mask, NULL); + pthread_sigmask(SIG_UNBLOCK, &mask, NULL); close(pipefd[1]); dup2(pipefd[0], STDIN_FILENO); @@ -443,7 +443,7 @@ log_pipe_init(struct log *log, const char *init_str) #endif #endif /* OK, let's hope for the best. */ - sigprocmask(SIG_UNBLOCK, &mask, NULL); + pthread_sigmask(SIG_UNBLOCK, &mask, NULL); close(pipefd[0]); log->fd = pipefd[1]; return 0; diff --git a/src/main.cc b/src/main.cc index a424073ed9..444f4a1fa5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -239,8 +239,8 @@ signal_reset(void) /* Unblock any signals blocked by libev. */ sigset_t sigset; sigfillset(&sigset); - if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) == -1) - say_syserror("sigprocmask"); + if (pthread_sigmask(SIG_UNBLOCK, &sigset, NULL) == -1) + say_syserror("pthread_sigmask"); } static void diff --git a/third_party/coro/coro.c b/third_party/coro/coro.c index 5028e3c146..125f715690 100644 --- a/third_party/coro/coro.c +++ b/third_party/coro/coro.c @@ -407,7 +407,7 @@ coro_create (coro_context *ctx, coro_func coro, void *arg, void *sptr, size_t ss sigemptyset (&nsig); sigaddset (&nsig, SIGUSR2); - sigprocmask (SIG_BLOCK, &nsig, &osig); + pthread_sigmask (SIG_BLOCK, &nsig, &osig); nsa.sa_handler = trampoline; sigemptyset (&nsa.sa_mask); @@ -450,7 +450,7 @@ coro_create (coro_context *ctx, coro_func coro, void *arg, void *sptr, size_t ss sigaltstack (&ostk, 0); sigaction (SIGUSR2, &osa, 0); - sigprocmask (SIG_SETMASK, &osig, 0); + pthread_sigmask (SIG_SETMASK, &osig, 0); # elif CORO_LOSER diff --git a/third_party/libev/ev.c b/third_party/libev/ev.c index cdda9a0ffa..04119bf987 100644 --- a/third_party/libev/ev.c +++ b/third_party/libev/ev.c @@ -4649,7 +4649,7 @@ ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT { /* TODO: check .head */ sigaddset (&sigfd_set, w->signum); - sigprocmask (SIG_BLOCK, &sigfd_set, 0); + pthread_sigmask (SIG_BLOCK, &sigfd_set, 0); signalfd (sigfd, &sigfd_set, 0); } @@ -4681,7 +4681,7 @@ ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT { sigemptyset (&sa.sa_mask); sigaddset (&sa.sa_mask, w->signum); - sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0); + pthread_sigmask (SIG_UNBLOCK, &sa.sa_mask, 0); } #endif } @@ -4717,7 +4717,7 @@ ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT sigdelset (&sigfd_set, w->signum); signalfd (sigfd, &sigfd_set, 0); - sigprocmask (SIG_UNBLOCK, &ss, 0); + pthread_sigmask (SIG_UNBLOCK, &ss, 0); } else #endif -- GitLab