shm, xwayland: prefer atomic close-on-exec without O_TMPFILE

Signed-off-by: Jan Beich <jbeich@FreeBSD.org>
Reviewed-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
Jan Beich
2017-07-07 16:31:48 +02:00
committed by Adam Jackson
parent 3e3b8a40fe
commit 1e23f03dd5
4 changed files with 12 additions and 3 deletions

View File

@@ -1195,7 +1195,6 @@ shm_tmpfile(void)
{
#ifdef SHMDIR
int fd;
int flags;
char template[] = SHMDIR "/shmfd-XXXXXX";
#ifdef O_TMPFILE
fd = open(SHMDIR, O_TMPFILE|O_RDWR|O_CLOEXEC|O_EXCL, 0666);
@@ -1205,15 +1204,21 @@ shm_tmpfile(void)
}
ErrorF ("Not using O_TMPFILE\n");
#endif
#ifdef HAVE_MKOSTEMP
fd = mkostemp(template, O_CLOEXEC);
#else
fd = mkstemp(template);
#endif
if (fd < 0)
return -1;
unlink(template);
flags = fcntl(fd, F_GETFD);
#ifndef HAVE_MKOSTEMP
int flags = fcntl(fd, F_GETFD);
if (flags != -1) {
flags |= FD_CLOEXEC;
(void) fcntl(fd, F_SETFD, &flags);
}
#endif
return fd;
#else
return -1;