]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
NPTL: Use __gen_tempname in sem_open. roland/tempname
authorRoland McGrath <roland@hack.frob.com>
Mon, 24 Nov 2014 19:30:54 +0000 (11:30 -0800)
committerRoland McGrath <roland@hack.frob.com>
Tue, 25 Nov 2014 00:18:17 +0000 (16:18 -0800)
ChangeLog
nptl/sem_open.c
stdio-common/Versions

index e37e0f487a4e92cf90298335c8f8c377ade2dca3..83c93d70a53d16d76e47a9f408c5ed841b2eb758 100644 (file)
--- 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.
index cf91859dabd6da1e776a9599b31bb3c3e3164709..4a318eb5c28aac8db43619c35ff98987f201b035 100644 (file)
@@ -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)
index 06b96f678a42d608087a8c72ba00f0a7b738c64e..920d4175cb77d034cd871a69e603acc964080886 100644 (file)
@@ -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;
   }