From 76a0c085c8fc6e5f2a46b186a4a1c83e3713bd76 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Tue, 11 Jan 2011 14:33:33 +0300 Subject: 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 --- src/corelib/kernel/qsystemsemaphore_unix.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/corelib/kernel/qsystemsemaphore_unix.cpp') 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 +#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; -- cgit v1.2.3