summaryrefslogtreecommitdiff
path: root/nptl/sem_open.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2016-08-20 11:23:08 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2016-09-15 11:14:25 -0300
commit91dd866ff1801b27e1db1e14a52eb89a213627e6 (patch)
tree05093e97e9c7ba82bc6ac393f27f96b27ecf6f93 /nptl/sem_open.c
parent980d25d53e748abd3365aeec0a1ccd1316b4e6d6 (diff)
nptl: Set sem_open as a non cancellation point (BZ #15765)
This patch changes sem_open to not act as a cancellation point. Cancellation is disable at start and reenable in function exit. It fixes BZ #15765. Tested on x86_64 and i686. [BZ #15765] * nptl/Makefile (tests): Add tst-sem16. * nptl/tst-sem16.c: New file. * nptl/sem_open.c (sem_open): Disable asynchronous cancellation.
Diffstat (limited to 'nptl/sem_open.c')
-rw-r--r--nptl/sem_open.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/nptl/sem_open.c b/nptl/sem_open.c
index 5b45fadd71..d10828637a 100644
--- a/nptl/sem_open.c
+++ b/nptl/sem_open.c
@@ -31,7 +31,7 @@
#include "semaphoreP.h"
#include <shm-directory.h>
#include <futex-internal.h>
-
+#include <libc-lock.h>
/* Comparison function for search of existing mapping. */
int
@@ -153,6 +153,13 @@ sem_open (const char *name, int oflag, ...)
/* Create the name of the final file in local variable SHM_NAME. */
SHM_GET_NAME (EINVAL, SEM_FAILED, SEM_SHM_PREFIX);
+ /* Disable asynchronous cancellation. */
+#ifdef __libc_ptf_call
+ int state;
+ __libc_ptf_call (__pthread_setcancelstate,
+ (PTHREAD_CANCEL_DISABLE, &state), 0);
+#endif
+
/* If the semaphore object has to exist simply open it. */
if ((oflag & O_CREAT) == 0 || (oflag & O_EXCL) == 0)
{
@@ -193,7 +200,8 @@ sem_open (const char *name, int oflag, ...)
if (value > SEM_VALUE_MAX)
{
__set_errno (EINVAL);
- return SEM_FAILED;
+ result = SEM_FAILED;
+ goto out;
}
/* Create the initial file content. */
@@ -233,7 +241,10 @@ sem_open (const char *name, int oflag, ...)
mode cannot later be set since then we cannot apply the
file create mask. */
if (__mktemp (tmpfname) == NULL)
- return SEM_FAILED;
+ {
+ result = SEM_FAILED;
+ goto out;
+ }
/* Open the file. Make sure we do not overwrite anything. */
fd = __libc_open (tmpfname, O_RDWR | O_CREAT | O_EXCL, mode);
@@ -247,7 +258,8 @@ sem_open (const char *name, int oflag, ...)
__set_errno (EAGAIN);
}
- return SEM_FAILED;
+ result = SEM_FAILED;
+ goto out;
}
/* We got a file. */
@@ -308,5 +320,10 @@ sem_open (const char *name, int oflag, ...)
errno = save;
}
+out:
+#ifdef __libc_ptf_call
+ __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0);
+#endif
+
return result;
}