diff --git a/shared/os-compatibility.c b/shared/os-compatibility.c index 78409d15..a9d91c52 100644 --- a/shared/os-compatibility.c +++ b/shared/os-compatibility.c @@ -40,6 +40,21 @@ #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 os_fd_set_cloexec(int fd) { diff --git a/shared/os-compatibility.h b/shared/os-compatibility.h index 6aaa2688..85f65854 100644 --- a/shared/os-compatibility.h +++ b/shared/os-compatibility.h @@ -30,6 +30,9 @@ #include +int +os_fd_clear_cloexec(int fd); + int os_fd_set_cloexec(int fd);