From: Marius Vlad Date: Mon, 19 Sep 2022 19:56:12 +0000 (+0300) Subject: shared: introduce os_fd_clear_cloexec() X-Git-Tag: 17.90.0~71 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=1b93121761e16117d1926e8d57bad17cc5b2701a;p=src%2Fagl-compositor.git 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. Bug-AGL: SPEC-4510 Signed-off-by: Pekka Paalanen Signed-off-by: Marius Vlad Change-Id: Ib2245394654651583f9d59785540962ae4cb8a28 --- diff --git a/shared/os-compatibility.c b/shared/os-compatibility.c index 4bf7d81..681a544 100644 --- a/shared/os-compatibility.c +++ b/shared/os-compatibility.c @@ -403,3 +403,18 @@ os_ro_anonymous_file_put_fd(int fd) return 0; } + +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; +} diff --git a/shared/os-compatibility.h b/shared/os-compatibility.h index 1ad45d7..c396c7d 100644 --- a/shared/os-compatibility.h +++ b/shared/os-compatibility.h @@ -69,4 +69,7 @@ os_ro_anonymous_file_get_fd(struct ro_anonymous_file *file, int os_ro_anonymous_file_put_fd(int fd); +int +os_fd_clear_cloexec(int fd); + #endif /* OS_COMPATIBILITY_H */