From bc7569b187e9a9ae5b651b747c7ece8044adf7d3 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 7 Jun 2024 00:20:46 +0200 Subject: Do a fork() --- c/cloexec/cloexec.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'c') 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 + #include #include -#include +#include #include +#include +#include #include 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); } -- cgit v1.2.3