aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-06-07 00:20:46 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-06-07 00:20:46 +0200
commitbc7569b187e9a9ae5b651b747c7ece8044adf7d3 (patch)
treea4cb83fd1e74a1a7bcaede8b386a554e42376beb
parent85f37eb9f6fd8b633d312dbd5471d06a75762956 (diff)
Do a fork()
-rw-r--r--c/cloexec/cloexec.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/c/cloexec/cloexec.c b/c/cloexec/cloexec.c
index ba899ee..50b7639 100644
--- a/c/cloexec/cloexec.c
+++ b/c/cloexec/cloexec.c
@@ -1,8 +1,12 @@
#define _GNU_SOURCE
+#include <sys/wait.h>
+
#include <assert.h>
#include <err.h>
-#include <paths.h>
+#include <errno.h>
#include <fcntl.h>
+#include <paths.h>
+#include <stdio.h>
#include <unistd.h>
int
@@ -22,5 +26,20 @@ main(void)
assert((fcntl(nfd, F_GETFD) & FD_CLOEXEC) != 0);
close(nfd);
- close(fd);
+
+ switch (fork()) {
+ case -1:
+ err(1, "fork");
+ case 0:
+ puts("If the FD for /dev/null is closed, this should list 4 items");
+ fflush(stdout);
+ execlp("ls", "ls", "/proc/self/fd", NULL);
+ err(1, "exec: true");
+ default:
+ if (wait(NULL) == -1)
+ err(1, "wait");
+ }
+
+ /* Not EBADF */
+ assert(close(fd) == 0);
}