/none/tests/tls
/none/tests/track-fds-exec-children
/none/tests/track_new
+/none/tests/track_std
/none/tests/unit_debuglog
/none/tests/use_after_close
/none/tests/valgrind_cpp_test
504101 Add a "vgstack" script
504177 FILE DESCRIPTORS banner shows when closing some inherited fds
501741 syscall cachestat not wrapped
+502359 Add --modify-fds=yes option
503969 Make test results of make ltpchecks compatible with bunsen
504265 FreeBSD: missing syscall wrappers for fchroot and setcred
504341 Valgrind killed by LTP syscall testcase setrlimit05
" startup exit abexit valgrindabexit all none\n"
" --track-fds=no|yes|all track open file descriptors? [no]\n"
" all includes reporting inherited file descriptors\n"
-" --modify-fds=no|high modify newly open file descriptors? [no]\n"
+" --modify-fds=no|yes|high modify newly open file descriptors? [no]\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"
}
else if VG_STR_CLO(arg, "--modify-fds", tmp_str) {
if (VG_(strcmp)(tmp_str, "high") == 0)
- VG_(clo_modify_fds) = 1;
+ VG_(clo_modify_fds) = VG_MODIFY_FD_HIGH;
+ else if (VG_(strcmp)(tmp_str, "yes") == 0)
+ VG_(clo_modify_fds) = VG_MODIFY_FD_YES;
else if (VG_(strcmp)(tmp_str, "no") == 0)
- VG_(clo_modify_fds) = 0;
+ VG_(clo_modify_fds) = VG_MODIFY_FD_NO;
else
VG_(fmsg_bad_option)(arg,
- "Bad argument, should be 'high' or 'no'\n");
+ "Bad argument, should be 'high', 'yes', or 'no'\n");
}
else if VG_BOOL_CLOM(cloPD, arg, "--trace-children", VG_(clo_trace_children)) {}
else if VG_BOOL_CLOM(cloPD, arg, "--child-silent-after-fork",
Bool VG_(clo_run_libc_freeres) = True;
Bool VG_(clo_run_cxx_freeres) = True;
UInt VG_(clo_track_fds) = 0;
-UInt VG_(clo_modify_fds) = 0;
+UInt VG_(clo_modify_fds) = VG_MODIFY_FD_NO;
Bool VG_(clo_show_below_main)= False;
Bool VG_(clo_keep_debuginfo) = False;
Bool VG_(clo_show_emwarns) = False;
/* Helper macro for POST handlers that return a new file in RES.
If possible sets RES (through SET_STATUS_Success) to a new
(not yet seem before) file descriptor. */
-#define POST_newFd_RES \
- do { \
- if (VG_(clo_modify_fds) == 1) { \
- int newFd = ML_(get_next_new_fd)(RES); \
- if (newFd != RES) \
- SET_STATUS_Success(newFd); \
- } \
+#define POST_newFd_RES \
+ do { \
+ if ((VG_(clo_modify_fds) == VG_MODIFY_FD_YES && RES > 2) \
+ || (VG_(clo_modify_fds) == VG_MODIFY_FD_HIGH)) { \
+ int newFd = ML_(get_next_new_fd)(RES); \
+ if (newFd != RES) \
+ SET_STATUS_Success(newFd); \
+ } \
} while (0)
/////////////////////////////////////////////////////////////////
<varlistentry id="opt.modify-fds" xreflabel="--modify-fds">
<term>
- <option><![CDATA[--modify-fds=<no|high> [default: no] ]]></option>
+ <option><![CDATA[--modify-fds=<no|yes|high> [default: no] ]]></option>
</term>
<listitem>
<para>When enabled, when the program opens a new file descriptor,
the highest available file descriptor is returned instead of the
- lowest one.</para>
+ lowest one. Use <option>yes</option> to restrict the feature from
+ the 0/1/2 file descriptors as they're often used for stdout/stderr
+ redirection.</para>
</listitem>
</varlistentry>
/* Track open file descriptors? 0 = No, 1 = Yes, 2 = All (including std) */
extern UInt VG_(clo_track_fds);
+/* Whether to adjust file descriptor numbers. Yes does for all nonstd file
+ descriptors. High does for all file descriptors. */
+#define VG_MODIFY_FD_NO 0
+#define VG_MODIFY_FD_YES 1
+#define VG_MODIFY_FD_HIGH 2
extern UInt VG_(clo_modify_fds);
fdbaduse.stderr.exp fdbaduse.vgtest \
use_after_close.stderr.exp use_after_close.vgtest \
track_new.stderr.exp track_new.stdout.exp \
- track_new.vgtest track_new.stderr.exp-illumos
-
+ track_new.vgtest track_new.stderr.exp-illumos \
+ track_yes.vgtest track_high.vgtest \
+ track_yes.stderr.exp track_high.stderr.exp
check_PROGRAMS = \
args \
file_dclose \
fdbaduse \
use_after_close \
- track_new
+ track_new \
+ track_std
if HAVE_STATIC_LIBC
if ! VGCONF_OS_IS_LINUX
startup exit abexit valgrindabexit all none
--track-fds=no|yes|all track open file descriptors? [no]
all includes reporting inherited file descriptors
- --modify-fds=no|high modify newly open file descriptors? [no]
+ --modify-fds=no|yes|high modify newly open file descriptors? [no]
--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>
startup exit abexit valgrindabexit all none
--track-fds=no|yes|all track open file descriptors? [no]
all includes reporting inherited file descriptors
- --modify-fds=no|high modify newly open file descriptors? [no]
+ --modify-fds=no|yes|high modify newly open file descriptors? [no]
--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>
--- /dev/null
+FILE DESCRIPTORS: 3 open (1 inherited) at exit.
+Open file descriptor ...: ...
+ ...
+
+Open file descriptor ...: /dev/null
+ ...
+
+
--- /dev/null
+prog: track_std
+vgopts: -q --track-fds=yes --modify-fds=high
+stderr_filter: filter_fdleak
+
--- /dev/null
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <string.h>
+
+int
+main (void)
+{
+ char buf[20];
+ size_t nbytes;
+ int ret;
+
+ /* close stdin */
+ close (0);
+ /* open /dev/null as new stdin */
+ (void)open ("/dev/null", O_RDONLY);
+ /* redirect stdout as stderr */
+ close (1);
+ /* stdout becomes stderr */
+ ret = dup (2);
+
+ if (ret == 1) {
+ strcpy(buf, "hello world\n");
+ nbytes = strlen(buf);
+
+ /* should come out on stderr */
+ write (1, buf, nbytes);
+ }
+
+ return 0;
+}
--- /dev/null
+hello world
+FILE DESCRIPTORS: 3 open (1 inherited) at exit.
+Open file descriptor ...: ...
+ ...
+
+Open file descriptor ...: /dev/null
+ ...
+
+
--- /dev/null
+prog: track_std
+vgopts: -q --track-fds=yes --modify-fds=yes
+stderr_filter: filter_fdleak
+