From: "Daniel P. Berrange" <[email protected]>

Even with the -q flag specified, tracing output is still mixed
with messages about signals and process exit status, which is
often irrelevant. Allow the -q flag to be repeated to force
the suppression of signals / exit status info too.

Before

  $ strace -q -e trace=execve -f ./fdstreamtest
  execve("./fdstreamtest", ["./fdstreamtest"], [/* 29 vars */]) = 0
  [pid 24812] +++ exited with 0 +++
  [pid 24811] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=24812, 
si_status=0, si_utime=0, si_stime=0} ---
  [pid 24811] +++ exited with 0 +++
  --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=24811, si_status=0, 
si_utime=0, si_stime=0} ---
  [pid 24813] +++ exited with 0 +++
  --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=24813, si_status=0, 
si_utime=0, si_stime=0} ---
  [pid 24816] execve("/usr/bin/sed", ["/usr/bin/sed", "s%/[^/]*$%%"], [/* 30 
vars */]) = 0
  [pid 24815] +++ exited with 0 +++
  [pid 24816] +++ exited with 0 +++
  [pid 24814] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=24815, 
si_status=0, si_utime=0, si_stime=0} ---
  [pid 24814] +++ exited with 0 +++
  --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=24814, si_status=0, 
si_utime=0, si_stime=0} ---
  [pid 24819] execve("/usr/bin/sed", ["/usr/bin/sed", "-n", "s/.*-> //p"], [/* 
30 vars */]) = 0
  [pid 24818] execve("/usr/bin/ls", ["ls", "-ld", "./fdstreamtest"], [/* 30 
vars */]) = 0

10 lines of noise, 4 lines of signal

...snip...

After

  $ strace -q -q -e trace=execve -f ./fdstreamtest  > /dev/null
  execve("./fdstreamtest", ["./fdstreamtest"], [/* 29 vars */]) = 0
  [pid 24835] execve("/usr/bin/sed", ["/usr/bin/sed", "s%/[^/]*$%%"], [/* 30 
vars */]) = 0
  [pid 24838] execve("/usr/bin/sed", ["/usr/bin/sed", "-n", "s/.*-> //p"], [/* 
30 vars */]) = 0
  [pid 24837] execve("/usr/bin/ls", ["ls", "-ld", "./fdstreamtest"], [/* 30 
vars */]) = 0

0 lines of noise, 4 lines of signal.

Signed-off-by: Daniel P. Berrange <[email protected]>
---
 defs.h   |  2 +-
 strace.1 |  4 ++++
 strace.c | 31 +++++++++++++++++--------------
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/defs.h b/defs.h
index 291b8fb..58cdf99 100644
--- a/defs.h
+++ b/defs.h
@@ -539,7 +539,7 @@ typedef enum {
 extern cflag_t cflag;
 extern bool debug_flag;
 extern bool Tflag;
-extern bool qflag;
+extern unsigned int qflag;
 extern bool not_failing_only;
 extern bool show_fd_path;
 /* are we filtering traces based on paths? */
diff --git a/strace.1 b/strace.1
index 00ca03c..9d628a1 100644
--- a/strace.1
+++ b/strace.1
@@ -267,6 +267,10 @@ Suppress messages about attaching, detaching etc.  This 
happens
 automatically when output is redirected to a file and the command
 is run directly instead of attaching.
 .TP
+.B \-qq
+If given twice, suppress messages about process exit status and
+signals received.
+.TP
 .B \-r
 Print a relative timestamp upon entry to each system call.  This
 records the time difference between the beginning of successive
diff --git a/strace.c b/strace.c
index 4cd5835..f6f6e89 100644
--- a/strace.c
+++ b/strace.c
@@ -74,7 +74,7 @@ unsigned int xflag = 0;
 bool need_fork_exec_workarounds = 0;
 bool debug_flag = 0;
 bool Tflag = 0;
-bool qflag = 0;
+unsigned int qflag = 0;
 /* Which WSTOPSIG(status) value marks syscall traps? */
 static unsigned int syscall_trap_sig = SIGTRAP;
 static unsigned int tflag = 0;
@@ -1609,7 +1609,7 @@ init(int argc, char *argv[])
                        iflag = 1;
                        break;
                case 'q':
-                       qflag = 1;
+                       qflag++;
                        break;
                case 'r':
                        rflag = 1;
@@ -2112,7 +2112,8 @@ trace(void)
                if (WIFEXITED(status)) {
                        if (pid == strace_child)
                                exit_code = WEXITSTATUS(status);
-                       if (cflag != CFLAG_ONLY_STATS) {
+                       if (cflag != CFLAG_ONLY_STATS &&
+                           qflag < 2) {
                                printleader(tcp);
                                tprintf("+++ exited with %d +++\n", 
WEXITSTATUS(status));
                                line_ended();
@@ -2221,17 +2222,19 @@ trace(void)
 # define PC_FORMAT_STR ""
 # define PC_FORMAT_ARG /* nothing */
 #endif
-                               printleader(tcp);
-                               if (!stopped) {
-                                       tprintf("--- %s ", signame(sig));
-                                       printsiginfo(&si, verbose(tcp));
-                                       tprintf(PC_FORMAT_STR " ---\n"
-                                               PC_FORMAT_ARG);
-                               } else
-                                       tprintf("--- stopped by %s" 
PC_FORMAT_STR " ---\n",
-                                               signame(sig)
-                                               PC_FORMAT_ARG);
-                               line_ended();
+                               if (qflag < 2) {
+                                       printleader(tcp);
+                                       if (!stopped) {
+                                               tprintf("--- %s ", 
signame(sig));
+                                               printsiginfo(&si, verbose(tcp));
+                                               tprintf(PC_FORMAT_STR " ---\n"
+                                                       PC_FORMAT_ARG);
+                                       } else
+                                               tprintf("--- stopped by %s" 
PC_FORMAT_STR " ---\n",
+                                                       signame(sig)
+                                                       PC_FORMAT_ARG);
+                                       line_ended();
+                               }
                        }
 
                        if (!stopped)
-- 
1.8.1.4


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Strace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to