diff --git a/Xext/shm.c b/Xext/shm.c index 4168951c4..15e1b67ff 100644 --- a/Xext/shm.c +++ b/Xext/shm.c @@ -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; diff --git a/configure.ac b/configure.ac index 180334d99..98b8ea2ed 100644 --- a/configure.ac +++ b/configure.ac @@ -157,7 +157,7 @@ dnl Checks for library functions. AC_CHECK_FUNCS([backtrace geteuid getuid issetugid getresuid \ getdtablesize getifaddrs getpeereid getpeerucred getprogname getzoneid \ mmap posix_fallocate seteuid shmctl64 strncasecmp vasprintf vsnprintf \ - walkcontext setitimer poll epoll_create1]) + walkcontext setitimer poll epoll_create1 mkostemp]) AC_CONFIG_LIBOBJ_DIR([os]) AC_REPLACE_FUNCS([reallocarray strcasecmp strcasestr strlcat strlcpy strndup\ timingsafe_memcmp]) diff --git a/include/dix-config.h.in b/include/dix-config.h.in index 44a29a69a..f12df74da 100644 --- a/include/dix-config.h.in +++ b/include/dix-config.h.in @@ -134,6 +134,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_FB_H +/* Define to 1 if you have the `mkostemp' function. */ +#undef HAVE_MKOSTEMP + /* Define to 1 if you have the `mmap' function. */ #undef HAVE_MMAP diff --git a/include/meson.build b/include/meson.build index c7830ef73..00ec0573d 100644 --- a/include/meson.build +++ b/include/meson.build @@ -119,6 +119,7 @@ conf_data.set('HAVE_GETPEEREID', cc.has_function('getpeereid')) conf_data.set('HAVE_GETPEERUCRED', cc.has_function('getpeerucred')) conf_data.set('HAVE_GETPROGNAME', cc.has_function('getprogname')) conf_data.set('HAVE_GETZONEID', cc.has_function('getzoneid')) +conf_data.set('HAVE_MKOSTEMP', cc.has_function('mkostemp')) conf_data.set('HAVE_MMAP', cc.has_function('mmap')) conf_data.set('HAVE_POLL', cc.has_function('poll')) conf_data.set('HAVE_POLLSET_CREATE', cc.has_function('pollset_create'))