shared: introduce os_fd_clear_cloexec()

This function will be used between fork() and exec() to remove the
close-on-exec flag. The first user will be compositor/xwayland.c.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 2 years ago committed by Pekka Paalanen
parent 0260b8a0b5
commit 99b2b958f9
  1. 15
      shared/os-compatibility.c
  2. 3
      shared/os-compatibility.h

@ -40,6 +40,21 @@
#define READONLY_SEALS (F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE) #define READONLY_SEALS (F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE)
int
os_fd_clear_cloexec(int fd)
{
int flags;
flags = fcntl(fd, F_GETFD);
if (flags == -1)
return -1;
if (fcntl(fd, F_SETFD, flags & ~(int)FD_CLOEXEC) == -1)
return -1;
return 0;
}
int int
os_fd_set_cloexec(int fd) os_fd_set_cloexec(int fd)
{ {

@ -30,6 +30,9 @@
#include <sys/types.h> #include <sys/types.h>
int
os_fd_clear_cloexec(int fd);
int int
os_fd_set_cloexec(int fd); os_fd_set_cloexec(int fd);

Loading…
Cancel
Save