diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index cec1ab2a0b1..ad39eaab585 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include +#include #include "qcore_unix_p.h" #include @@ -19,6 +20,21 @@ QT_BEGIN_NAMESPACE +void qt_ignore_sigpipe() noexcept // noexcept: sigaction(2) is not a Posix Cancellation Point +{ + // Set to ignore SIGPIPE once only. + Q_CONSTINIT static QBasicAtomicInt atom = Q_BASIC_ATOMIC_INITIALIZER(0); + if (!atom.loadRelaxed()) { + // More than one thread could turn off SIGPIPE at the same time + // But that's acceptable because they all would be doing the same + // action + struct sigaction noaction = {}; + noaction.sa_handler = SIG_IGN; + ::sigaction(SIGPIPE, &noaction, nullptr); + atom.storeRelaxed(1); + } +} + QByteArray qt_readlink(const char *path) { #ifndef PATH_MAX diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index cad1c4f54ee..e94ac711c50 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -18,7 +18,6 @@ #include "qplatformdefs.h" #include -#include "qatomic.h" #include "qbytearray.h" #include "qdeadlinetimer.h" @@ -181,21 +180,7 @@ inline timespec qAbsTimespec(timespec ts) return normalizedTimespec(ts); } -inline void qt_ignore_sigpipe() -{ - // Set to ignore SIGPIPE once only. - Q_CONSTINIT static QBasicAtomicInt atom = Q_BASIC_ATOMIC_INITIALIZER(0); - if (!atom.loadRelaxed()) { - // More than one thread could turn off SIGPIPE at the same time - // But that's acceptable because they all would be doing the same - // action - struct sigaction noaction; - memset(&noaction, 0, sizeof(noaction)); - noaction.sa_handler = SIG_IGN; - ::sigaction(SIGPIPE, &noaction, nullptr); - atom.storeRelaxed(1); - } -} +Q_CORE_EXPORT void qt_ignore_sigpipe() noexcept; #if defined(Q_PROCESSOR_X86_32) && defined(__GLIBC__) # if !__GLIBC_PREREQ(2, 22)