From 91dd866ff1801b27e1db1e14a52eb89a213627e6 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Sat, 20 Aug 2016 11:23:08 -0300 Subject: 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. --- nptl/sem_open.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'nptl/sem_open.c') 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 #include - +#include /* 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; } -- cgit v1.2.3