summaryrefslogtreecommitdiffstats
path: root/libpthread/nptl/sem_open.c
diff options
context:
space:
mode:
authorMikhail Gusarov <dottedmag@dottedmag.net>2009-11-08 02:33:16 +0600
committerAustin Foxley <austinf@cetoncorp.com>2009-11-09 14:39:08 -0800
commit8ce4b857ab234368df4379354029c1b02bd0afac (patch)
tree862dd0a4e954d95fb2d1bf06ffec2310c1d4e760 /libpthread/nptl/sem_open.c
parent7c5a18c19270347359fc14048900dadb45096817 (diff)
downloaduClibc-alpine-8ce4b857ab234368df4379354029c1b02bd0afac.tar.bz2
uClibc-alpine-8ce4b857ab234368df4379354029c1b02bd0afac.tar.xz
Unbreak sem_open when UCLIBC_SUSV3_LEGACY is not defined
sem_open uses mktemp to create temporary file. Reimplement it using __gen_tmpname, removing ugly while(1) loop. As a side-effect remove the potential source of EAGAIN errors. Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net> Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
Diffstat (limited to 'libpthread/nptl/sem_open.c')
-rw-r--r--libpthread/nptl/sem_open.c37
1 files changed, 5 insertions, 32 deletions
diff --git a/libpthread/nptl/sem_open.c b/libpthread/nptl/sem_open.c
index 3bada7d46..b7279fa78 100644
--- a/libpthread/nptl/sem_open.c
+++ b/libpthread/nptl/sem_open.c
@@ -34,6 +34,7 @@
#include <sys/statfs.h>
#include <linux_fsinfo.h>
#include "semaphoreP.h"
+#include "../../misc/internals/tempname.h"
/* Compatibility defines. */
@@ -327,39 +328,11 @@ sem_open (const char *name, int oflag, ...)
tmpfname = (char *) alloca (mountpoint.dirlen + 6 + 1);
char *xxxxxx = mempcpy (tmpfname, mountpoint.dir, mountpoint.dirlen);
+ strcpy (xxxxxx, "XXXXXX");
- int retries = 0;
-#define NRETRIES 50
- while (1)
- {
- /* Add the suffix for mktemp. */
- strcpy (xxxxxx, "XXXXXX");
-
- /* We really want to use mktemp here. We cannot use mkstemp
- since the file must be opened with a specific mode. The
- mode cannot later be set since then we cannot apply the
- file create mask. */
- if (mktemp (tmpfname) == NULL)
- return SEM_FAILED;
-
- /* Open the file. Make sure we do not overwrite anything. */
- fd = __libc_open (tmpfname, O_RDWR | O_CREAT | O_EXCL, mode);
- if (fd == -1)
- {
- if (errno == EEXIST)
- {
- if (++retries < NRETRIES)
- continue;
-
- __set_errno (EAGAIN);
- }
-
- return SEM_FAILED;
- }
-
- /* We got a file. */
- break;
- }
+ fd = __gen_tempname (tmpfname, __GT_FILE, mode);
+ if (fd == -1)
+ return SEM_FAILED;
if (TEMP_FAILURE_RETRY (__libc_write (fd, &initsem, sizeof (sem_t)))
== sizeof (sem_t)