1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

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.
This commit is contained in:
Adhemerval Zanella
2016-08-20 11:23:08 -03:00
parent 980d25d53e
commit 91dd866ff1
4 changed files with 157 additions and 5 deletions

View File

@ -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;
}