summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@hack.frob.com>2014-11-24 11:30:54 -0800
committerRoland McGrath <roland@hack.frob.com>2014-11-24 16:18:17 -0800
commit3dbc4418f2691cba858e788ea3523a82ea073afd (patch)
tree72ef4bb8316fb2adc0fe10baf06b37b152e3e638
parent77d4f6d1ed90a2ccb5bc6fd6d19f67f19de7fbcd (diff)
downloadglibc-roland/tempname.tar.gz
NPTL: Use __gen_tempname in sem_open.roland/tempname
-rw-r--r--ChangeLog6
-rw-r--r--nptl/sem_open.c46
-rw-r--r--stdio-common/Versions3
3 files changed, 21 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index e37e0f487a..83c93d70a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2014-11-24 Roland McGrath <roland@hack.frob.com>
+ * nptl/sem_open.c (sem_open): Use __gen_tempname with
+ __gen_tempname_try_file and custom MODE value, rather than
+ using __mktemp and open in a loop.
+ * stdio-common/Versions (GLIBC_PRIVATE): Add __gen_tempname,
+ __gen_tempname_try_file.
+
* sysdeps/posix/tempname.c (__gen_tempname): Instead of FLAGS and KIND
arguments, take a function pointer TRY_NAME and void *TRY_NAME_ARG.
Call that *TRY_NAME to try a candidate name.
diff --git a/nptl/sem_open.c b/nptl/sem_open.c
index cf91859dab..4a318eb5c2 100644
--- a/nptl/sem_open.c
+++ b/nptl/sem_open.c
@@ -318,40 +318,18 @@ sem_open (const char *name, int oflag, ...)
sizeof (sem_t) - sizeof (struct new_sem));
tmpfname = (char *) alloca (mountpoint.dirlen + 6 + 1);
- char *xxxxxx = __mempcpy (tmpfname, mountpoint.dir, mountpoint.dirlen);
-
- 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;
- }
+ strcpy (__mempcpy (tmpfname, mountpoint.dir, mountpoint.dirlen),
+ "XXXXXX");
+
+ /* This is just like mkstemp, but with a specific mode. */
+ fd = __gen_tempname (tmpfname, 0,
+ &__gen_tempname_try_file, &((int[2]) { 0, mode }));
+ if (fd < 0)
+ {
+ if (errno == EEXIST)
+ __set_errno (EAGAIN);
+ return SEM_FAILED;
+ }
if (TEMP_FAILURE_RETRY (__libc_write (fd, &sem.initsem, sizeof (sem_t)))
== sizeof (sem_t)
diff --git a/stdio-common/Versions b/stdio-common/Versions
index 06b96f678a..920d4175cb 100644
--- a/stdio-common/Versions
+++ b/stdio-common/Versions
@@ -58,6 +58,9 @@ libc {
register_printf_modifier; register_printf_type; register_printf_specifier;
}
GLIBC_PRIVATE {
+ __gen_tempname;
+ __gen_tempname_try_file;
+
# global variables
_itoa_lower_digits;
}