From 7399dea9603c30f142a45c3952626425dd91aca0 Mon Sep 17 00:00:00 2001 From: Simon Chopin Date: Wed, 27 Aug 2025 17:56:12 +0200 Subject: [PATCH] testlib: add expected argument to fcntl(F_DUPFD) The F_DUPFD and its relative F_DUPFD_CLOEXEC both expect an int argument as extra argument, being the minimal value for the new FD. This argument must be within the accepted range (see ulimit -H -n). This was detected in Ubuntu during testing against the latest glibc, stracing resulted in: 107244 fcntl(1, F_DUPFD_CLOEXEC, 1847846346272) = -1 EINVAL (Invalid argument) On the system in question (ppc64el machine running Ubuntu Questing), the relevant limit is 524288. For the fix we use 3 as a reasonable floor value, as in the first one after stderr. It also happens to be the one used in revokefs/main.c. Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/2121039 --- tests/testlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testlib.c b/tests/testlib.c index 41f27ac9..90c0f0b4 100644 --- a/tests/testlib.c +++ b/tests/testlib.c @@ -257,7 +257,7 @@ tests_stdout_to_stderr_begin (void) { TestsStdoutToStderr *original = g_new0 (TestsStdoutToStderr, 1); - original->fd = fcntl (STDOUT_FILENO, F_DUPFD_CLOEXEC); + original->fd = fcntl (STDOUT_FILENO, F_DUPFD_CLOEXEC, 3); if (original->fd < 0) g_error ("fcntl F_DUPFD_CLOEXEC: %s", g_strerror (errno));