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>
This commit is contained in:
Pekka Paalanen 2022-07-07 11:34:44 +03:00 committed by Pekka Paalanen
parent 0260b8a0b5
commit 99b2b958f9
2 changed files with 18 additions and 0 deletions

View File

@ -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)
{ {

View File

@ -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);