[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in test-fcntl.c
From: |
Bruno Haible |
Subject: |
Re: Bug in test-fcntl.c |
Date: |
Fri, 14 May 2021 23:53:46 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-206-generic; KDE/5.18.0; x86_64; ; ) |
Nicholas Gaya wrote:
> The process hierarchy starts with tclsh (MacPorts), then a bunch of layers of
> make and sh (from oath-toolkit's recursive `make check`), and finally the
> test-fcntl executable. I was using MacPorts' "trace mode", which seems to be
> responsible for the particularly high number of inherited open files, but
> without trace mode I still run into the issue; the returned fd is 11 in this
> case.
Thanks; that gives a hint also who is eating up the file descriptors 3 to 10.
> But I don't really want to focus on my specific use-case (for which I already
> have a workaround). I think the patch is warranted just on the basis that it
> makes the test a bit more robust, with minimal drawbacks.
Yes. But I wanted to have a description of the cause, that I can include in
comments.
Done. Thanks for the report!
2021-05-14 Bruno Haible <bruno@clisp.org>
fcntl tests: Avoid failure in MacPorts.
Reported by Nicholas Gaya <nicholasgaya@gmail.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-05/msg00014.html>.
* tests/test-fcntl.c (main): Close fd 10 before assuming that it is
closed.
* tests/test-execute-main.c: Update comment.
diff --git a/tests/test-execute-main.c b/tests/test-execute-main.c
index a6a9fe4..372ff1d 100644
--- a/tests/test-execute-main.c
+++ b/tests/test-execute-main.c
@@ -69,7 +69,8 @@ main (int argc, char *argv[])
Such file descriptors have been seen:
- with GNU make, when invoked as 'make -j N' with j > 1,
- in some versions of the KDE desktop environment,
- - on NetBSD.
+ - on NetBSD,
+ - in MacPorts with the "trace mode" enabled.
*/
#if HAVE_CLOSE_RANGE
if (close_range (3, 20 - 1, 0) < 0)
diff --git a/tests/test-fcntl.c b/tests/test-fcntl.c
index caf629d..cb834b4 100644
--- a/tests/test-fcntl.c
+++ b/tests/test-fcntl.c
@@ -415,6 +415,16 @@ main (int argc, char *argv[])
ASSERT (close (fd) == 0);
ASSERT (unlink (file) == 0);
+ /* Close file descriptors that may have been inherited from the parent
+ process and that would cause failures below.
+ Such file descriptors have been seen:
+ - with GNU make, when invoked as 'make -j N' with j > 1,
+ - in some versions of the KDE desktop environment,
+ - on NetBSD,
+ - in MacPorts with the "trace mode" enabled.
+ */
+ (void) close (10);
+
/* Test whether F_DUPFD_CLOEXEC is effective. */
ASSERT (fcntl (1, F_DUPFD_CLOEXEC, 10) >= 0);
#if defined _WIN32 && !defined __CYGWIN__