]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Treat all inherited file descriptors the same with --track-fds.
authorMark Wielaard <mark@klomp.org>
Thu, 23 Jan 2025 14:50:52 +0000 (15:50 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 23 Jan 2025 14:50:52 +0000 (15:50 +0100)
We used to special case 0, 1, 2 (stdin/out/err) specially even when
they were not inherited (anymore). Now the --track-fds=[yes|all]
option treats all inherited file descriptors the same. And if any
inherited file descriptor gets closed and reopened then they are
now treated as normal non-inherited file descriptors.

https://bugs.kde.org/show_bug.cgi?id=487296

22 files changed:
NEWS
coregrind/m_main.c
coregrind/m_syswrap/syswrap-generic.c
memcheck/tests/freebsd/pdfork_pdkill.stderr.exp
memcheck/tests/freebsd/timerfd.stderr.exp
none/tests/cmdline1.stdout.exp
none/tests/cmdline1.stdout.exp-non-linux
none/tests/cmdline2.stdout.exp
none/tests/cmdline2.stdout.exp-non-linux
none/tests/fdleak_cmsg.stderr.exp
none/tests/fdleak_cmsg_supp.stderr.exp
none/tests/fdleak_creat.stderr.exp
none/tests/fdleak_creat_sup.stderr.exp
none/tests/fdleak_dup.stderr.exp
none/tests/fdleak_dup2.stderr.exp
none/tests/fdleak_fcntl.stderr.exp
none/tests/fdleak_ipv4.stderr.exp
none/tests/fdleak_open.stderr.exp
none/tests/fdleak_pipe.stderr.exp
none/tests/fdleak_socketpair.stderr.exp
none/tests/freebsd/umtx_shm_creat1.stderr.exp
none/tests/freebsd/umtx_shm_creat2.stderr.exp

diff --git a/NEWS b/NEWS
index 5c576ff33e4c6679126dcf5305ba38df936a0c05..22744917eb42a0e1927a9bc8e4915237606a7781 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,11 @@ AMD64/macOS 10.13 and nanoMIPS/Linux.
 
 * ==================== TOOL CHANGES ===================
 
+* The --track-fds=yes and --track-fds=all options now treat all
+  inherited file descriptors the same as 0, 1, 2 (stdin/out/err).
+  And when the stdin/out/err descriptors are reassigned they are
+  now treated as normal (non-inherited) file descriptors.
+
 * ==================== FIXED BUGS ====================
 
 The following bugs have been fixed or resolved.  Note that "n-i-bz"
@@ -27,6 +32,8 @@ bugzilla (https://bugs.kde.org/enter_bug.cgi?product=valgrind) rather
 than mailing the developers (or mailing lists) directly -- bugs that
 are not entered into bugzilla tend to get forgotten about or ignored.
 
+487296  --track-fds=yes and --track-fds=all report erroneous information
+        when fds 0, 1, or 2 are used as non-std
 489913  WARNING: unhandled amd64-linux syscall: 444 (landlock_create_ruleset)
 494246  syscall fsopen not wrapped
 494327  Crash when running Helgrind built with #define TRACE_PTH_FNS 1
index 3eba026cc53381a5014c6d8c0039e4b5650373fe..3f07e57a91703bbad756bdbd703e8c4db00c2056 100644 (file)
@@ -114,7 +114,7 @@ static void usage_NORETURN ( int need_help )
 "         where event is one of:\n"
 "           startup exit abexit valgrindabexit all none\n"
 "    --track-fds=no|yes|all    track open file descriptors? [no]\n"
-"                              all includes reporting stdin, stdout and stderr\n"
+"                              all includes reporting inherited file descriptors\n"
 "    --time-stamp=no|yes       add timestamps to log messages? [no]\n"
 "    --log-fd=<number>         log messages to file descriptor [2=stderr]\n"
 "    --log-file=<file>         log messages to <file>\n"
index bfe4c6fe06b12105fb64a9e62fedb1cc98b8191a..a74b8f1d216ecc2df0a9f2148a84a1504a554aa8 100644 (file)
@@ -941,30 +941,30 @@ HChar *getsockdetails(Int fd, UInt len, HChar *buf)
 void VG_(show_open_fds) (const HChar* when)
 {
    OpenFd *i;
-   int non_std = 0;
+   int inherited = 0;
 
    for (i = allocated_fds; i; i = i->next) {
-      if (i->fd > 2 && i->fd_closed != True)
-         non_std++;
+      if (i->where == NULL)
+         inherited++;
    }
 
    /* If we are running quiet and there are either no open file descriptors
       or not tracking all fds, then don't report anything.  */
    if ((fd_count == 0
-        || ((non_std == 0) && (VG_(clo_track_fds) < 2)))
+        || ((fd_count - inherited == 0) && (VG_(clo_track_fds) < 2)))
        && (VG_(clo_verbosity) == 0))
       return;
 
    if (!VG_(clo_xml)) {
-      VG_(umsg)("FILE DESCRIPTORS: %d open (%d std) %s.\n",
-                fd_count, fd_count - non_std, when);
+      VG_(umsg)("FILE DESCRIPTORS: %d open (%d inherited) %s.\n",
+                fd_count, inherited, when);
    }
 
    for (i = allocated_fds; i; i = i->next) {
       if (i->fd_closed)
          continue;
 
-      if (i->fd <= 2 && VG_(clo_track_fds) < 2)
+      if (i->where == NULL && VG_(clo_track_fds) < 2)
           continue;
 
       struct NotClosedExtra nce;
index 018489c62f76eab2cda4b98c3c868a57f0515426..bab0469badd6fa7bd0cdc801d3024315fbbf1ca4 100644 (file)
@@ -28,7 +28,7 @@ Syscall param pdfork(flags) contains uninitialised byte(s)
    ...
    by 0x........: main (pdfork_pdkill.c:96)
 
-FILE DESCRIPTORS: 3 open (3 std) at exit.
+FILE DESCRIPTORS: 3 open (3 inherited) at exit.
 Open file descriptor ...
    <inherited from parent>
 
index 4831ec8061f535eee67e9a585a2040bc8d349b8b..beff4e6fc3e689cbcaad7f5c19ef16e466ed15c3 100644 (file)
@@ -32,7 +32,7 @@ Syscall param timerfd_settime(fd) contains uninitialised byte(s)
    at 0x........: timerfd_settime (in /...libc...)
    by 0x........: main (timerfd.c:141)
 
-FILE DESCRIPTORS: 4 open (3 std) at exit.
+FILE DESCRIPTORS: 4 open (3 inherited) at exit.
 Open file descriptor 3:
    at 0x........: timerfd_create (in /...libc...)
    by 0x........: main (timerfd.c:115)
index c7b7536856c3be70b4cea82f3baf31dc12dbcc85..464c58f42aa7f8f8bfaaecadad65b381b00ce3ea 100644 (file)
@@ -29,7 +29,7 @@ usage: valgrind [options] prog-and-args
          where event is one of:
            startup exit abexit valgrindabexit all none
     --track-fds=no|yes|all    track open file descriptors? [no]
-                              all includes reporting stdin, stdout and stderr
+                              all includes reporting inherited file descriptors
     --time-stamp=no|yes       add timestamps to log messages? [no]
     --log-fd=<number>         log messages to file descriptor [2=stderr]
     --log-file=<file>         log messages to <file>
index 6650cc5b9011fb065e7af5a5afecca84bdd09e3c..f0534f824c54b24a4b4f1de62c1b5f62ea17af29 100644 (file)
@@ -29,7 +29,7 @@ usage: valgrind [options] prog-and-args
          where event is one of:
            startup exit abexit valgrindabexit all none
     --track-fds=no|yes|all    track open file descriptors? [no]
-                              all includes reporting stdin, stdout and stderr
+                              all includes reporting inherited file descriptors
     --time-stamp=no|yes       add timestamps to log messages? [no]
     --log-fd=<number>         log messages to file descriptor [2=stderr]
     --log-file=<file>         log messages to <file>
index 24ca407f806dc95b9a1487bdc92bd302d6a679c9..fe526855d8f8615e1328b417335d903c41d75f53 100644 (file)
@@ -29,7 +29,7 @@ usage: valgrind [options] prog-and-args
          where event is one of:
            startup exit abexit valgrindabexit all none
     --track-fds=no|yes|all    track open file descriptors? [no]
-                              all includes reporting stdin, stdout and stderr
+                              all includes reporting inherited file descriptors
     --time-stamp=no|yes       add timestamps to log messages? [no]
     --log-fd=<number>         log messages to file descriptor [2=stderr]
     --log-file=<file>         log messages to <file>
index e13d196954e694c806322629c3629fccca32aada..e518644ab548c6a8e73ad68fc5aa8c8c6fb93d4a 100644 (file)
@@ -29,7 +29,7 @@ usage: valgrind [options] prog-and-args
          where event is one of:
            startup exit abexit valgrindabexit all none
     --track-fds=no|yes|all    track open file descriptors? [no]
-                              all includes reporting stdin, stdout and stderr
+                              all includes reporting inherited file descriptors
     --time-stamp=no|yes       add timestamps to log messages? [no]
     --log-fd=<number>         log messages to file descriptor [2=stderr]
     --log-file=<file>         log messages to <file>
index 0fe56eaeed11ac773b596b5ac84fcebf8ef80ddb..6b3b53fc7c8fe6e90c48b783160ca66f334f4a76 100644 (file)
@@ -1,6 +1,6 @@
 
 
-FILE DESCRIPTORS: 7 open (3 std) at exit.
+FILE DESCRIPTORS: 7 open (3 inherited) at exit.
 Open AF_UNIX socket ...: /tmp/sock
    ...
 
@@ -24,7 +24,7 @@ Open file descriptor ...: /dev/null
 
 
 
-FILE DESCRIPTORS: 6 open (3 std) at exit.
+FILE DESCRIPTORS: 6 open (3 inherited) at exit.
 Open file descriptor ...: /tmp/data2
    ...
 
index a7d8cc42e24c58875905a12dc40b9896d7c267a5..f2636d2da4a978c50527738d8a94521f439e44ea 100644 (file)
@@ -1,6 +1,6 @@
 
 
-FILE DESCRIPTORS: 7 open (3 std) at exit.
+FILE DESCRIPTORS: 7 open (3 inherited) at exit.
 Open file descriptor ...: ...
    <inherited from parent>
 
@@ -12,7 +12,7 @@ Open file descriptor ...: /dev/null
 
 
 
-FILE DESCRIPTORS: 6 open (3 std) at exit.
+FILE DESCRIPTORS: 6 open (3 inherited) at exit.
 Open file descriptor ...: ...
    <inherited from parent>
 
index 7b70478b9d4619d125d4a4ce32410cbb1f152f56..b4954bc0e1be664a9a0738934f562dab6c1c83bd 100644 (file)
@@ -1,6 +1,6 @@
 
 
-FILE DESCRIPTORS: 4 open (3 std) at exit.
+FILE DESCRIPTORS: 4 open (3 inherited) at exit.
 Open file descriptor ...: /tmp/file
    ...
 
index c02a807356ee93b49f3fbf4a6bde93c57447e13a..094b516ce515eef449bb2a6553985342a5cb77f8 100644 (file)
@@ -1,6 +1,6 @@
 
 
-FILE DESCRIPTORS: 4 open (3 std) at exit.
+FILE DESCRIPTORS: 4 open (3 inherited) at exit.
 Open file descriptor ...: ...
    <inherited from parent>
 
index 8ceada9230cec4e901441e52b6d1ef155c687aad..1ed7d8c26b34103c982f38f49616cf0c4439b802 100644 (file)
@@ -1,6 +1,6 @@
 
 
-FILE DESCRIPTORS: 5 open (3 std) at exit.
+FILE DESCRIPTORS: 5 open (3 inherited) at exit.
 Open file descriptor ...: /dev/null
    ...
 
index 4576a578b3b456f1a1ab511755cb25a4f578a3a0..8c2cbefa183e1376d045a768c7c93c24fc38e337 100644 (file)
@@ -1,6 +1,6 @@
 
 
-FILE DESCRIPTORS: 6 open (3 std) at exit.
+FILE DESCRIPTORS: 6 open (3 inherited) at exit.
 Open file descriptor ...: /dev/null
    ...
 
index 8ceada9230cec4e901441e52b6d1ef155c687aad..1ed7d8c26b34103c982f38f49616cf0c4439b802 100644 (file)
@@ -1,6 +1,6 @@
 
 
-FILE DESCRIPTORS: 5 open (3 std) at exit.
+FILE DESCRIPTORS: 5 open (3 inherited) at exit.
 Open file descriptor ...: /dev/null
    ...
 
index 801b0279f811f8a28bf70851877718fcf6065d72..4560caf69c10aa572cf1696708c81f879ec01e3f 100644 (file)
@@ -12,7 +12,7 @@ File descriptor ...: ... is already closed
    by 0x........: client (fdleak_ipv4.c:68)
    by 0x........: main
 
-FILE DESCRIPTORS: 5 open (3 std) at exit.
+FILE DESCRIPTORS: 5 open (3 inherited) at exit.
 Open AF_INET socket 4: 127.0.0.1:... <-> 127.0.0.1:...
    ...
 
@@ -21,7 +21,7 @@ Open AF_INET socket 3: 127.0.0.1:... <-> <unbound>
 
 
 
-FILE DESCRIPTORS: 4 open (3 std) at exit.
+FILE DESCRIPTORS: 4 open (3 inherited) at exit.
 Open AF_INET socket 3: 127.0.0.1:... <-> 127.0.0.1:...
    ...
 
index f3f51167f154b271c233ba7059cedd3580b60b27..348f99edcd320447f1f808c776bc8f8c4f292c71 100644 (file)
@@ -1,6 +1,6 @@
 
 
-FILE DESCRIPTORS: 4 open (3 std) at exit.
+FILE DESCRIPTORS: 4 open (3 inherited) at exit.
 Open file descriptor ...: /dev/null
    ...
 
index 5f92ea69c2c9abecd5b0b277993bb64d3c1a7084..34b6a8f8cd56446f35d47922967abe4664aa65c8 100644 (file)
@@ -1,6 +1,6 @@
 
 
-FILE DESCRIPTORS: 5 open (3 std) at exit.
+FILE DESCRIPTORS: 5 open (3 inherited) at exit.
 Open file descriptor ...:
    ...
 
index 73832a108b1737fdb2733debbe7ea52e9b140bc5..d6f6d10c6ec82442e0dccdeed0c88ab0e47dcf48 100644 (file)
@@ -1,6 +1,6 @@
 
 
-FILE DESCRIPTORS: 5 open (3 std) at exit.
+FILE DESCRIPTORS: 5 open (3 inherited) at exit.
 Open AF_UNIX socket ...: <unknown>
    ...
 
index 4e918760ffff511651725a911d68373432874801..d7f95030612817d7da5de9460829ed4f16ade816 100644 (file)
@@ -1,4 +1,4 @@
-FILE DESCRIPTORS: 3 open (3 std) at exit.
+FILE DESCRIPTORS: 3 open (3 inherited) at exit.
 Open file descriptor ...: ...
    <inherited from parent>
 
index 4acc5e412284d4efd483892e946cd78c025ecda6..1504b8d18f7f5ab55c2343067d09a0b8c8580ee6 100644 (file)
@@ -1,4 +1,4 @@
-FILE DESCRIPTORS: 4 open (3 std) at exit.
+FILE DESCRIPTORS: 4 open (3 inherited) at exit.
 Open file descriptor ...:
    ...