From bf67518b53a7d843112ef3a5a44ce93e523a3739 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 May 2023 16:04:30 -0700 Subject: [PATCH] QProcess/Unix: don't set the SIGPIPE signal handler twice If the user is asking us to ignore it, don't set to the default behavior. Change-Id: Ib5ce7a497e034ebabb2cfffd17628562f745358d Reviewed-by: Oswald Buddenhagen Reviewed-by: Volker Hilsheimer --- src/corelib/io/qprocess_unix.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index cb1144f6dc5..efada360058 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -799,8 +799,6 @@ static void callChildProcessModifier(const QProcessPrivate *d) noexcept // still sharing memory with the parent process. void QChildProcess::startProcess() const noexcept { - QtVforkSafe::change_sigpipe(SIG_DFL); // reset the signal that we ignored - // Render channels configuration. d->commitChannels(); @@ -811,6 +809,7 @@ void QChildProcess::startProcess() const noexcept if (workingDirectory >= 0 && fchdir(workingDirectory) == -1) failChildProcess(d, "fchdir", errno); + bool sigpipeHandled = false; if (d->unixExtras) { // FIRST we call the user modifier function, before we dropping // privileges or closing non-standard file descriptors @@ -818,6 +817,13 @@ void QChildProcess::startProcess() const noexcept // then we apply our other user-provided parameters applyProcessParameters(d->unixExtras->processParameters); + + auto flags = d->unixExtras->processParameters.flags; + sigpipeHandled = flags.testAnyFlags(QProcess::ResetSignalHandlers | QProcess::IgnoreSigPipe); + } + if (!sigpipeHandled) { + // reset the signal that we ignored + QtVforkSafe::change_sigpipe(SIG_DFL); // reset the signal that we ignored } // execute the process