From 14cefe7c645a3148165f4b2fa6095d9446e378c7 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sun, 16 Jun 2024 21:23:08 +0200 Subject: [PATCH 13/15] Don't leave fds created with --log-file, --xml-file or --log-socket open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit prepare_sink_fd and prepare_sink_socket will create a new file descriptor for the output sink. finalize_sink_fd then copies the fd to the safe range, so it doesn't conflict with any application fds. If we created the original fd ourselves, it was a VgLogTo_File or VgLogTo_Socket, not VgLogTo_Fd, finalize_sink_fd should close it. Also close socket when connecting fails in VG_(connect_via_socket). Add a testcase for --log-file and --xml-file which prints output to /dev/stderr https://bugs.kde.org/show_bug.cgi?id=202770 https://bugs.kde.org/show_bug.cgi?id=311655 https://bugs.kde.org/show_bug.cgi?id=488379 Co-authored-by: Alexandra Hájková fd = safe_fd; + /* If we created the new_fd (VgLogTo_File or VgLogTo_Socket), then we + don't need the original file descriptor open anymore. We only need + to keep it open if it was an existing fd given by the user (or + stderr). */ + if (sink->type != VgLogTo_Fd) + VG_(close)(new_fd); } } diff --git a/none/tests/Makefile.am b/none/tests/Makefile.am index 185993f204bb..532cc7632a8f 100644 --- a/none/tests/Makefile.am +++ b/none/tests/Makefile.am @@ -86,6 +86,7 @@ dist_noinst_SCRIPTS = \ filter_none_discards \ filter_stderr \ filter_timestamp \ + filter_xml \ allexec_prepare_prereq noinst_HEADERS = fdleak.h @@ -229,7 +230,9 @@ EXTRA_DIST = \ sigprocmask.stderr.exp sigprocmask.vgtest \ socket_close.stderr.exp socket_close.vgtest \ file_dclose.stderr.exp file_dclose.vgtest \ - double_close_range.stderr.exp double_close_range.vgtest + double_close_range.stderr.exp double_close_range.vgtest \ + log-track-fds.stderr.exp log-track-fds.vgtest \ + xml-track-fds.stderr.exp xml-track-fds.vgtest check_PROGRAMS = \ diff --git a/none/tests/filter_xml b/none/tests/filter_xml new file mode 100755 index 000000000000..d1ef570a05b0 --- /dev/null +++ b/none/tests/filter_xml @@ -0,0 +1,25 @@ +#! /bin/sh + +dir=`dirname $0` + +# FreeBSD adds this one extra line +# but after filter_xml_frames it will just be ...<\/path> +# which matches other lines, so get rid of it while we can +# uniquely match it +sed "/internet<\/path>/d" | + +$dir/../../tests/filter_xml_frames | +perl -p -e "s/