summaryrefslogtreecommitdiffstats
path: root/shared/os-compatibility.c
diff options
context:
space:
mode:
authorMarius Vlad <marius.vlad@collabora.com>2022-09-19 22:56:12 +0300
committerMarius Vlad <marius.vlad@collabora.com>2022-09-22 14:13:21 +0300
commit1b93121761e16117d1926e8d57bad17cc5b2701a (patch)
tree69e2849f1227eba5c6fff180aa84276410f6cb44 /shared/os-compatibility.c
parentd08a5b2010f6e6feb1642ebf8e8444c4091d70dc (diff)
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 <pekka.paalanen@collabora.com> Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Change-Id: Ib2245394654651583f9d59785540962ae4cb8a28
Diffstat (limited to 'shared/os-compatibility.c')
-rw-r--r--shared/os-compatibility.c15
1 files changed, 15 insertions, 0 deletions
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;
+}