From: Mark Wielaard Date: Thu, 23 Jan 2025 14:50:52 +0000 (+0100) Subject: Treat all inherited file descriptors the same with --track-fds. X-Git-Tag: VALGRIND_3_25_0~173 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9f0e4107c140b47ea2a9c097afcac73a8454e17f;p=thirdparty%2Fvalgrind.git Treat all inherited file descriptors the same with --track-fds. 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 --- diff --git a/NEWS b/NEWS index 5c576ff33..22744917e 100644 --- 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 diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 3eba026cc..3f07e57a9 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -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= log messages to file descriptor [2=stderr]\n" " --log-file= log messages to \n" diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index bfe4c6fe0..a74b8f1d2 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -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; diff --git a/memcheck/tests/freebsd/pdfork_pdkill.stderr.exp b/memcheck/tests/freebsd/pdfork_pdkill.stderr.exp index 018489c62..bab0469ba 100644 --- a/memcheck/tests/freebsd/pdfork_pdkill.stderr.exp +++ b/memcheck/tests/freebsd/pdfork_pdkill.stderr.exp @@ -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 ... diff --git a/memcheck/tests/freebsd/timerfd.stderr.exp b/memcheck/tests/freebsd/timerfd.stderr.exp index 4831ec806..beff4e6fc 100644 --- a/memcheck/tests/freebsd/timerfd.stderr.exp +++ b/memcheck/tests/freebsd/timerfd.stderr.exp @@ -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) diff --git a/none/tests/cmdline1.stdout.exp b/none/tests/cmdline1.stdout.exp index c7b753685..464c58f42 100644 --- a/none/tests/cmdline1.stdout.exp +++ b/none/tests/cmdline1.stdout.exp @@ -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= log messages to file descriptor [2=stderr] --log-file= log messages to diff --git a/none/tests/cmdline1.stdout.exp-non-linux b/none/tests/cmdline1.stdout.exp-non-linux index 6650cc5b9..f0534f824 100644 --- a/none/tests/cmdline1.stdout.exp-non-linux +++ b/none/tests/cmdline1.stdout.exp-non-linux @@ -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= log messages to file descriptor [2=stderr] --log-file= log messages to diff --git a/none/tests/cmdline2.stdout.exp b/none/tests/cmdline2.stdout.exp index 24ca407f8..fe526855d 100644 --- a/none/tests/cmdline2.stdout.exp +++ b/none/tests/cmdline2.stdout.exp @@ -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= log messages to file descriptor [2=stderr] --log-file= log messages to diff --git a/none/tests/cmdline2.stdout.exp-non-linux b/none/tests/cmdline2.stdout.exp-non-linux index e13d19695..e518644ab 100644 --- a/none/tests/cmdline2.stdout.exp-non-linux +++ b/none/tests/cmdline2.stdout.exp-non-linux @@ -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= log messages to file descriptor [2=stderr] --log-file= log messages to diff --git a/none/tests/fdleak_cmsg.stderr.exp b/none/tests/fdleak_cmsg.stderr.exp index 0fe56eaee..6b3b53fc7 100644 --- a/none/tests/fdleak_cmsg.stderr.exp +++ b/none/tests/fdleak_cmsg.stderr.exp @@ -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 ... diff --git a/none/tests/fdleak_cmsg_supp.stderr.exp b/none/tests/fdleak_cmsg_supp.stderr.exp index a7d8cc42e..f2636d2da 100644 --- a/none/tests/fdleak_cmsg_supp.stderr.exp +++ b/none/tests/fdleak_cmsg_supp.stderr.exp @@ -1,6 +1,6 @@ -FILE DESCRIPTORS: 7 open (3 std) at exit. +FILE DESCRIPTORS: 7 open (3 inherited) at exit. Open file descriptor ...: ... @@ -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 ...: ... diff --git a/none/tests/fdleak_creat.stderr.exp b/none/tests/fdleak_creat.stderr.exp index 7b70478b9..b4954bc0e 100644 --- a/none/tests/fdleak_creat.stderr.exp +++ b/none/tests/fdleak_creat.stderr.exp @@ -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 ... diff --git a/none/tests/fdleak_creat_sup.stderr.exp b/none/tests/fdleak_creat_sup.stderr.exp index c02a80735..094b516ce 100644 --- a/none/tests/fdleak_creat_sup.stderr.exp +++ b/none/tests/fdleak_creat_sup.stderr.exp @@ -1,6 +1,6 @@ -FILE DESCRIPTORS: 4 open (3 std) at exit. +FILE DESCRIPTORS: 4 open (3 inherited) at exit. Open file descriptor ...: ... diff --git a/none/tests/fdleak_dup.stderr.exp b/none/tests/fdleak_dup.stderr.exp index 8ceada923..1ed7d8c26 100644 --- a/none/tests/fdleak_dup.stderr.exp +++ b/none/tests/fdleak_dup.stderr.exp @@ -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 ... diff --git a/none/tests/fdleak_dup2.stderr.exp b/none/tests/fdleak_dup2.stderr.exp index 4576a578b..8c2cbefa1 100644 --- a/none/tests/fdleak_dup2.stderr.exp +++ b/none/tests/fdleak_dup2.stderr.exp @@ -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 ... diff --git a/none/tests/fdleak_fcntl.stderr.exp b/none/tests/fdleak_fcntl.stderr.exp index 8ceada923..1ed7d8c26 100644 --- a/none/tests/fdleak_fcntl.stderr.exp +++ b/none/tests/fdleak_fcntl.stderr.exp @@ -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 ... diff --git a/none/tests/fdleak_ipv4.stderr.exp b/none/tests/fdleak_ipv4.stderr.exp index 801b0279f..4560caf69 100644 --- a/none/tests/fdleak_ipv4.stderr.exp +++ b/none/tests/fdleak_ipv4.stderr.exp @@ -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:... <-> -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:... ... diff --git a/none/tests/fdleak_open.stderr.exp b/none/tests/fdleak_open.stderr.exp index f3f51167f..348f99edc 100644 --- a/none/tests/fdleak_open.stderr.exp +++ b/none/tests/fdleak_open.stderr.exp @@ -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 ... diff --git a/none/tests/fdleak_pipe.stderr.exp b/none/tests/fdleak_pipe.stderr.exp index 5f92ea69c..34b6a8f8c 100644 --- a/none/tests/fdleak_pipe.stderr.exp +++ b/none/tests/fdleak_pipe.stderr.exp @@ -1,6 +1,6 @@ -FILE DESCRIPTORS: 5 open (3 std) at exit. +FILE DESCRIPTORS: 5 open (3 inherited) at exit. Open file descriptor ...: ... diff --git a/none/tests/fdleak_socketpair.stderr.exp b/none/tests/fdleak_socketpair.stderr.exp index 73832a108..d6f6d10c6 100644 --- a/none/tests/fdleak_socketpair.stderr.exp +++ b/none/tests/fdleak_socketpair.stderr.exp @@ -1,6 +1,6 @@ -FILE DESCRIPTORS: 5 open (3 std) at exit. +FILE DESCRIPTORS: 5 open (3 inherited) at exit. Open AF_UNIX socket ...: ... diff --git a/none/tests/freebsd/umtx_shm_creat1.stderr.exp b/none/tests/freebsd/umtx_shm_creat1.stderr.exp index 4e918760f..d7f950306 100644 --- a/none/tests/freebsd/umtx_shm_creat1.stderr.exp +++ b/none/tests/freebsd/umtx_shm_creat1.stderr.exp @@ -1,4 +1,4 @@ -FILE DESCRIPTORS: 3 open (3 std) at exit. +FILE DESCRIPTORS: 3 open (3 inherited) at exit. Open file descriptor ...: ... diff --git a/none/tests/freebsd/umtx_shm_creat2.stderr.exp b/none/tests/freebsd/umtx_shm_creat2.stderr.exp index 4acc5e412..1504b8d18 100644 --- a/none/tests/freebsd/umtx_shm_creat2.stderr.exp +++ b/none/tests/freebsd/umtx_shm_creat2.stderr.exp @@ -1,4 +1,4 @@ -FILE DESCRIPTORS: 4 open (3 std) at exit. +FILE DESCRIPTORS: 4 open (3 inherited) at exit. Open file descriptor ...: ...