From d75414372d4e27e1fe31d9cffea3e4fa938a21f3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 May 2023 10:19:04 -0700 Subject: [PATCH] QProcess/Unix: reset the signal block if ResetSignalHandlers requested This amends commit f9c87cfd44bcf4b90cb45354252ef19f647b0469 to reset the signal block mask too, not just the signal handlers. For this, SIGPIPE is not treated specially. Change-Id: Ib5ce7a497e034ebabb2cfffd17627289614bf315 Reviewed-by: Oswald Buddenhagen Reviewed-by: Volker Hilsheimer (cherry picked from commit 062b2ac71bac1e0449eff7f8f02cb0020ad39991) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qprocess_unix.cpp | 5 ++++ .../testUnixProcessParameters/main.cpp | 25 ++++++++++++++----- .../auto/corelib/io/qprocess/tst_qprocess.cpp | 9 +++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index b7c7c4bab41..7cd379f9fd2 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -660,6 +660,11 @@ static void applyProcessParameters(const QProcess::UnixProcessParameters ¶ms if (!ignore_sigpipe || sig != SIGPIPE) QtVforkSafe::sigaction(sig, &sa, nullptr); } + + // and unmask all signals + sigset_t set; + sigemptyset(&set); + sigprocmask(SIG_SETMASK, &set, nullptr); } // Close all file descriptors above stderr. diff --git a/tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp b/tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp index e701677403d..9be19306677 100644 --- a/tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp +++ b/tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp @@ -30,17 +30,30 @@ int main(int argc, char **argv) } if (cmd == "reset-sighand") { - // confirm it was not ignored + bool ok = true; + + // confirm our signal block mask is empty + sigset_t set; + sigprocmask(SIG_SETMASK, nullptr, &set); + for (int signo = 1; signo < NSIG; ++signo) { + if (sigismember(&set, signo)) { + fprintf(stderr, "'%s' is blocked.\n", strsignal(signo)); + ok = false; + } + } + + // confirm SIGUSR1 was not ignored struct sigaction action; sigaction(SIGUSR1, nullptr, &action); - if (action.sa_handler == SIG_DFL) - return EXIT_SUCCESS; - fprintf(stderr, "SIGUSR1 is SIG_IGN\n"); - return EXIT_FAILURE; + if (action.sa_handler != SIG_DFL) { + fprintf(stderr, "SIGUSR1 is SIG_IGN\n"); + ok = false; + } + return ok ? EXIT_SUCCESS : EXIT_FAILURE; } if (cmd == "ignore-sigpipe") { - // confirm it was ignored + // confirm SIGPIPE was ignored struct sigaction action; sigaction(SIGPIPE, nullptr, &action); if (action.sa_handler == SIG_IGN) diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 7c318f0ca7f..609a6e11138 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -1562,6 +1562,11 @@ void tst_QProcess::unixProcessParameters() sigaction(SIGUSR1, &act, &old_sigusr1); act.sa_handler = SIG_DFL; sigaction(SIGPIPE, &act, &old_sigpipe); + + // and we block SIGUSR2 + sigset_t *set = &act.sa_mask; // reuse this sigset_t + sigaddset(set, SIGUSR2); + sigprocmask(SIG_BLOCK, set, nullptr); } ~Scope() { @@ -1574,6 +1579,10 @@ void tst_QProcess::unixProcessParameters() sigaction(SIGUSR1, &old_sigusr1, nullptr); sigaction(SIGPIPE, &old_sigpipe, nullptr); devnull = -1; + + sigset_t *set = &old_sigusr1.sa_mask; // reuse this sigset_t + sigaddset(set, SIGUSR2); + sigprocmask(SIG_BLOCK, set, nullptr); } } scope;