-/* Copyright (C) 2002-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <fcntl.h>
#include "semaphoreP.h"
#include <shm-directory.h>
#include <futex-internal.h>
-
+#include <libc-lock.h>
/* Comparison function for search of existing mapping. */
int
/* 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)
{
if (value > SEM_VALUE_MAX)
{
__set_errno (EINVAL);
- return SEM_FAILED;
+ result = SEM_FAILED;
+ goto out;
}
/* Create the initial file content. */
sem.newsem.data = value;
#else
sem.newsem.value = value << SEM_VALUE_SHIFT;
- /* pad is used as a mutex on pre-v9 sparc and ignored otherwise. */
- sem.newsem.pad = 0;
sem.newsem.nwaiters = 0;
#endif
+ /* pad is used as a mutex on pre-v9 sparc and ignored otherwise. */
+ sem.newsem.pad = 0;
+
/* This always is a shared semaphore. */
sem.newsem.private = FUTEX_SHARED;
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);
__set_errno (EAGAIN);
}
- return SEM_FAILED;
+ result = SEM_FAILED;
+ goto out;
}
/* We got a file. */
errno = save;
}
+out:
+#ifdef __libc_ptf_call
+ __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0);
+#endif
+
return result;
}