]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
test: Close all descriptors before initializing them for closefrom()
authorGuillem Jover <guillem@hadrons.org>
Mon, 8 Jan 2024 00:58:54 +0000 (01:58 +0100)
committerGuillem Jover <guillem@hadrons.org>
Mon, 8 Jan 2024 00:58:54 +0000 (01:58 +0100)
On macOS, closefrom() only sets the close-on-exec flag, so we cannot
check whether all file descriptors were closed, which means that if
on entry our file descriptor table was filled after the 4th file
descriptor, then we might fail the assertions for the flags for odd
file descriptors which we expect to be closed.

This can easily happen when running the test suite in parallel mode
with «make -j8 check» for example.

Closes: #23
test/closefrom.c

index 474c69f65409d2fedd9d332915cb5973bdcc2711..f9d74cc0752d7e814520bd8b29056e8023d2c185 100644 (file)
@@ -40,6 +40,12 @@ main(int argc, char *argv[])
        fd = open("/dev/null", O_RDONLY);
 
        fd_max = 1024;
+
+       /* First make sure we have a clean fd list. */
+       for (i = 4; i < fd_max; i++)
+               close(i);
+
+       /* Then initialize each even fd. */
        for (i = 4; i < fd_max; i *= 2) {
                int fd_new = dup2(fd, i);