Bug 467714 - fdleak_* and rlimit tests fail when parent process has more than 64 descriptors opened.
Summary: fdleak_* and rlimit tests fail when parent process has more than 64 descripto...
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.19.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Mark Wielaard
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-23 12:12 UTC by Jesus Checa
Modified: 2023-04-14 22:15 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
close all file descriptors > 2 with CLOSE_INHERITED_FDS (1.84 KB, text/plain)
2023-03-23 12:25 UTC, Mark Wielaard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jesus Checa 2023-03-23 12:12:17 UTC
We found out that none/tests/fdleak_* and note/tests/rlimit{,64}_nofile tests fail if the parent process has more than 64 opened file descriptors.

These tests starts by closing all the inherited descriptors to have a known state at start/end of the test by calling.
However this macro only closes the range [3,64] as defined in none/tests/fdleak.h:

#define CLOSE_INHERITED_FDS { int i; for (i = 3; i < 64; i++) close(i); }

It would be great to close up to MAXFDS instead.
Comment 1 Mark Wielaard 2023-03-23 12:25:16 UTC
Created attachment 157527 [details]
close all file descriptors > 2 with CLOSE_INHERITED_FDS
Comment 2 Mark Wielaard 2023-03-23 12:40:21 UTC
Tested with:

 #include <stdlib.h>
 #include <unistd.h>
 int main (int argc, char *const argv[])
 {
   for (int i = 0; i < 100; ++i)
     dup (1);
   execvp (argv[1], argv + 1);
   exit (1);
 }

gcc -o dup100 dup100.c

./dup100 valgrind --track-fds=yes /bin/true
 ==673839== FILE DESCRIPTORS: 103 open (3 std) at exit.
 ==673839== Open file descriptor 102: /dev/pts/5
 ==673839==    <inherited from parent>
 [...]

 ./dup100 perl tests/vg_regtest none/tests/fdleak*vgtest
all fail
 with patch all succeed
\o/
Comment 3 Mark Wielaard 2023-04-14 22:15:32 UTC
commit 16be0ca4ba53154642bd45e6aa60ffba57369a0c
Author: Mark Wielaard <mark@klomp.org>
Date:   Sat Apr 15 00:13:57 2023 +0200

    tests fdleak.h close all open file descriptors > 2
    
    Use sysconf (_SC_OPEN_MAX) to find the upper limit. Or use 1024
    if that fails.
    
    https://bugs.kde.org/show_bug.cgi?id=467714