diff options
author | Roland McGrath <roland@hack.frob.com> | 2014-11-24 11:30:54 -0800 |
---|---|---|
committer | Roland McGrath <roland@hack.frob.com> | 2014-11-24 16:18:17 -0800 |
commit | 3dbc4418f2691cba858e788ea3523a82ea073afd (patch) | |
tree | 72ef4bb8316fb2adc0fe10baf06b37b152e3e638 /nptl/sem_open.c | |
parent | 77d4f6d1ed90a2ccb5bc6fd6d19f67f19de7fbcd (diff) | |
download | glibc-3dbc4418f2691cba858e788ea3523a82ea073afd.tar.gz |
NPTL: Use __gen_tempname in sem_open.roland/tempname
Diffstat (limited to 'nptl/sem_open.c')
-rw-r--r-- | nptl/sem_open.c | 46 |
1 files changed, 12 insertions, 34 deletions
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) |