]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a new flag, --child-silent-after-fork=no|yes [no]. When enabled,
authorJulian Seward <jseward@acm.org>
Sat, 17 Nov 2007 22:29:25 +0000 (22:29 +0000)
committerJulian Seward <jseward@acm.org>
Sat, 17 Nov 2007 22:29:25 +0000 (22:29 +0000)
causes child processes after fork to fall completely silent, which can
make the output a lot less confusing.  In addition it is pretty much
essential in XML output mode, so as to avoid mixing up any child XML
output with the parent's.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7177

coregrind/m_libcprint.c
coregrind/m_main.c
coregrind/m_options.c
coregrind/m_syswrap/syswrap-aix5.c
coregrind/m_syswrap/syswrap-generic.c
coregrind/m_syswrap/syswrap-linux.c
coregrind/pub_core_options.h

index a5129ef66abf38042882c2cb6ad1ca8741787fba..5ba8bb11d5fbbcbe93130054d6f2f415cb0ae3a2 100644 (file)
@@ -53,7 +53,12 @@ Bool VG_(logging_to_socket) = False;
 static void send_bytes_to_logging_sink ( Char* msg, Int nbytes )
 {
    if (!VG_(logging_to_socket)) {
-      VG_(write)( VG_(clo_log_fd), msg, nbytes );
+      /* VG_(clo_log_fd) could have been set to -1 in the various
+         sys-wrappers for sys_fork, if --child-silent-after-fork=yes
+         is in effect.  That is a signal that we should not produce
+         any more output. */
+      if (VG_(clo_log_fd) >= 0)
+         VG_(write)( VG_(clo_log_fd), msg, nbytes );
    } else {
       Int rc = VG_(write_socket)( VG_(clo_log_fd), msg, nbytes );
       if (rc == -1) {
index ca9dc4b98df1b46dae877f9fbd7f4cbc78eff4f1..50f6cbb21803a7661c363709ee08289b1c01fc1a 100644 (file)
@@ -114,7 +114,8 @@ static void usage_NORETURN ( Bool debug_help )
 "    --version                 show version\n"
 "    -q --quiet                run silently; only print error msgs\n"
 "    -v --verbose              be more verbose, incl counts of errors\n"
-"    --trace-children=no|yes   Valgrind-ise child processes? [no]\n"
+"    --trace-children=no|yes   Valgrind-ise child processes (follow execve)? [no]\n"
+"    --child-silent-after-fork=no|yes  omit child output between fork & exec? [no]\n"
 "    --track-fds=no|yes        track 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"
@@ -370,6 +371,8 @@ static Bool process_cmd_line_options( UInt* client_auxv, const char* toolname )
       else VG_BOOL_CLO(arg, "--time-stamp",       VG_(clo_time_stamp))
       else VG_BOOL_CLO(arg, "--track-fds",        VG_(clo_track_fds))
       else VG_BOOL_CLO(arg, "--trace-children",   VG_(clo_trace_children))
+      else VG_BOOL_CLO(arg, "--child-silent-after-fork",
+                            VG_(clo_child_silent_after_fork))
       else VG_BOOL_CLO(arg, "--trace-sched",      VG_(clo_trace_sched))
       else VG_BOOL_CLO(arg, "--trace-signals",    VG_(clo_trace_signals))
       else VG_BOOL_CLO(arg, "--trace-symtab",     VG_(clo_trace_symtab))
index f5ed2846b2cb3e0a3353f196837c30ef1e95e3a7..febf82c7de3fd3ffa0a340f90e023b06c0cbf3c2 100644 (file)
@@ -50,7 +50,8 @@ Bool   VG_(clo_xml)            = False;
 HChar* VG_(clo_xml_user_comment) = NULL;
 Bool   VG_(clo_demangle)       = True;
 Bool   VG_(clo_trace_children) = False;
-Int    VG_(clo_log_fd)         = 2;
+Bool   VG_(clo_child_silent_after_fork) = False;
+Int    VG_(clo_log_fd)         = 2; /* must be signed, as -1 is possible. */
 Char*  VG_(clo_log_name)       = NULL;
 Char*  VG_(clo_log_file_qualifier) = NULL;
 Bool   VG_(clo_time_stamp)     = False;
index 2ac521a6c9b3aba01df1d5be0e8801c26e6c4142..a5617db081fbeb2cd4664f67f78e4f394686246a 100644 (file)
@@ -1321,13 +1321,22 @@ PRE(sys_kfork) /* COPY OF GENERIC */
    SET_STATUS_from_SysRes( VG_(do_syscall0)(__NR_fork) );
 
    if (SUCCESS && RES == 0) {
+      /* child */
       VG_(do_atfork_child)(tid);
 
       /* restore signal mask */
       VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
+
+      /* If --child-silent-after-fork=yes was specified, set the
+         logging file descriptor to an 'impossible' value.  This is
+         noticed by send_bytes_to_logging_sink in m_libcprint.c, which
+         duly stops writing any further logging output. */
+      if (!VG_(logging_to_socket) && VG_(clo_child_silent_after_fork))
+         VG_(clo_log_fd) = -1;
    } 
    else 
    if (SUCCESS && RES > 0) {
+      /* parent */
       PRINT("   fork: process %d created child %d\n", VG_(getpid)(), RES);
 
       /* restore signal mask */
index 936539412e93102d2a9bcc606b2303e4b0d639eb..ccea5c5fb0497aa2e62f6f472047b31ebf8ba3ba 100644 (file)
@@ -2895,13 +2895,22 @@ PRE(sys_fork)
    SET_STATUS_from_SysRes( VG_(do_syscall0)(__NR_fork) );
 
    if (SUCCESS && RES == 0) {
+      /* child */
       VG_(do_atfork_child)(tid);
 
       /* restore signal mask */
       VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
+
+      /* If --child-silent-after-fork=yes was specified, set the
+         logging file descriptor to an 'impossible' value.  This is
+         noticed by send_bytes_to_logging_sink in m_libcprint.c, which
+         duly stops writing any further logging output. */
+      if (!VG_(logging_to_socket) && VG_(clo_child_silent_after_fork))
+         VG_(clo_log_fd) = -1;
    } 
    else 
    if (SUCCESS && RES > 0) {
+      /* parent */
       PRINT("   fork: process %d created child %d\n", VG_(getpid)(), RES);
 
       /* restore signal mask */
index 96cbe3714935235c4320c1a73623cf04064c126d..c1769e5a89afe9833d7087b9472f075a477aa895 100644 (file)
@@ -333,6 +333,13 @@ SysRes ML_(do_fork_clone) ( ThreadId tid, UInt flags,
 
       /* restore signal mask */
       VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
+
+      /* If --child-silent-after-fork=yes was specified, set the
+         logging file descriptor to an 'impossible' value.  This is
+         noticed by send_bytes_to_logging_sink in m_libcprint.c, which
+         duly stops writing any further logging output. */
+      if (!VG_(logging_to_socket) && VG_(clo_child_silent_after_fork))
+         VG_(clo_log_fd) = -1;
    } 
    else 
    if (!res.isError && res.res > 0) {
index 09b97fcd1f2dcbf5fbc436f914e49f0482267e9d..15d33f6b15ab503d4a630a25db65a944ba95687f 100644 (file)
@@ -61,6 +61,12 @@ extern Int   VG_(clo_sanity_level);
 extern Bool  VG_(clo_demangle);
 /* Simulate child processes? default: NO */
 extern Bool  VG_(clo_trace_children);
+/* After a fork, the child's output can become confusingly
+   intermingled with the parent's output.  This is especially
+   problematic when VG_(clo_xml) is True.  Setting
+   VG_(clo_child_silent_after_fork) causes children to fall silent
+   after fork() calls. */
+extern Bool  VG_(clo_child_silent_after_fork);
 
 /* Where logging output is to be sent to.