diff options
author | Thiago Macieira <[email protected]> | 2012-09-11 15:36:54 +0200 |
---|---|---|
committer | The Qt Project <[email protected]> | 2012-09-18 14:11:53 +0200 |
commit | 3f970c20f9afd5c9a1cc14d7f69882e13f6aaf1b (patch) | |
tree | 7e13275cafbfb8b10190571317ebd76d8191582e /src/network/socket/qnativesocketengine_unix.cpp | |
parent | 849f1f9efda601bcfd3760256205a2014e0bc936 (diff) |
Fix thread-safety of qt_ignore_sigpipe
The testAndSet operation would mean another thread could see the value
of 1 and proceed to write(2)/sendto(2) before SIGPIPE had been ignored.
If the pipe or socket were already closed by then, a SIGPIPE would be
delivered to the application with its default action: terminate.
Change-Id: I62dc8f5fa14c1dd453d13e4053c642bd78fbc468
Reviewed-by: Qt Doc Bot <[email protected]>
Reviewed-by: Oswald Buddenhagen <[email protected]>
Reviewed-by: Shane Kearns <[email protected]>
Reviewed-by: Peter Hartmann <[email protected]>
Diffstat (limited to 'src/network/socket/qnativesocketengine_unix.cpp')
-rw-r--r-- | src/network/socket/qnativesocketengine_unix.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index 4b22f1c262e..c73bbed088f 100644 --- a/src/network/socket/qnativesocketengine_unix.cpp +++ b/src/network/socket/qnativesocketengine_unix.cpp @@ -103,11 +103,15 @@ static void qt_ignore_sigpipe() #ifndef Q_NO_POSIX_SIGNALS // Set to ignore SIGPIPE once only. static QBasicAtomicInt atom = Q_BASIC_ATOMIC_INITIALIZER(0); - if (atom.testAndSetRelaxed(0, 1)) { + if (!atom.load()) { + // 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, 0); + atom.store(1); } #else // Posix signals are not supported by the underlying platform |