summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qsystemsemaphore_unix.cpp
diff options
context:
space:
mode:
authorRitt Konstantin <ritt.ks@gmail.com>2011-01-11 14:33:33 +0300
committerOlivier Goffart <olivier.goffart@nokia.com>2011-01-11 13:48:52 +0100
commit76a0c085c8fc6e5f2a46b186a4a1c83e3713bd76 (patch)
treecd0b52553dfa158dea815d9ed8841c053e0a3b57 /src/corelib/kernel/qsystemsemaphore_unix.cpp
parent54db2506e8f228487c109ec7efc7a2a9681e9087 (diff)
make the modifySemaphore() signal-safe on linux
as POSIX man says, if semop() is interrupted by a signal, it shall return -1 and set errno to EINTR. in qcore_unix_p.h, we have EINTR_LOOP helper macro exactly for such cases ;) Task-number: QTBUG-14434 Merge-request: 998 Reviewed-by: Olivier Goffart
Diffstat (limited to 'src/corelib/kernel/qsystemsemaphore_unix.cpp')
-rw-r--r--src/corelib/kernel/qsystemsemaphore_unix.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/corelib/kernel/qsystemsemaphore_unix.cpp b/src/corelib/kernel/qsystemsemaphore_unix.cpp
index 07e361885d..9d0c0b98e8 100644
--- a/src/corelib/kernel/qsystemsemaphore_unix.cpp
+++ b/src/corelib/kernel/qsystemsemaphore_unix.cpp
@@ -56,6 +56,8 @@
#include <sys/sem.h>
+#include "private/qcore_unix_p.h"
+
// OpenBSD 4.2 doesn't define EIDRM, see BUGS section:
// http://www.openbsd.org/cgi-bin/man.cgi?query=semop&manpath=OpenBSD+4.2
#if defined(Q_OS_OPENBSD) && !defined(EIDRM)
@@ -218,7 +220,10 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count)
operation.sem_num = 0;
operation.sem_op = count;
operation.sem_flg = SEM_UNDO;
- if (-1 == semop(semaphore, &operation, 1)) {
+
+ register int res;
+ EINTR_LOOP(res, semop(semaphore, &operation, 1));
+ if (-1 == res) {
// If the semaphore was removed be nice and create it and then modifySemaphore again
if (errno == EINVAL || errno == EIDRM) {
semaphore = -1;