]> granicus.if.org Git - strace/commitdiff
strace-log-merge: fix error diagnostics
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 18 Mar 2019 19:06:47 +0000 (19:06 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 18 Mar 2019 19:06:47 +0000 (19:06 +0000)
* strace-log-merge: Print error diagnostics and exit with a non-zero
status in case of no strace output.
* NEWS: Mention this fix.
* tests/strace-log-merge-error.test: New test.
* tests/Makefile.am (MISC_TESTS): Add it.

Fixes: v4.21~287 "strace-log-merge: work around corner cases of strace -ttt parsing"
NEWS
strace-log-merge
tests/Makefile.am
tests/strace-log-merge-error.test [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 3b6224b534760c3d4c8a25a7e3efa593cd040854..3bdfd0e0151ceb4a2b382789f29e45845e78a74a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,7 @@ Noteworthy changes in release ?.?? (????-??-??)
   * Fixed build in --with-libiberty=yes mode.
   * Fixed potential NULL dereference during printing of line continuation
     for syscalls that haven't been decoded.
+  * Fixed strace-log-merge error diagnostics.
 
 Noteworthy changes in release 4.26 (2018-12-26)
 ===============================================
index 87998c538f1f6ee76ac756420254a764203f6aef..9ef5705be25e0423dbce805334c6e6b856b151d8 100755 (executable)
@@ -3,7 +3,7 @@
 # This script processes strace -ff -tt output.  It merges the contents of all
 # STRACE_LOG.PID files and sorts them, printing result on the standard output.
 #
-# Copyright (c) 2012-2018 The strace developers.
+# Copyright (c) 2012-2019 The strace developers.
 #
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
@@ -44,8 +44,10 @@ for file in "$logfile".*; do
        # grep -v '^$' removes empty lines which may result.
        sed -n "s/^\($dd:\)\?\($dd:\)\?\($ds\.\)\?$ds /\2\4\6\7 $pid \0/p" < "$file"
        echo
-done \
-| sort -s -n -k1,1 | sed -n 's/^[0-9][0-9]* //p'
+done |
+       sort -s -n -k1,1 |
+       sed -n 's/^[0-9][0-9]* //p' |
+       grep -v '^$'
 
 rc=$?
 [ $rc -eq 1 ] &&
index 68da797ac306f93e17dc6fea1f36557134c436d6..553ff5e19c1dd777792e0a1b6312929bf505603b 100644 (file)
@@ -341,6 +341,7 @@ MISC_TESTS = \
        strace-T.test \
        strace-V.test \
        strace-ff.test \
+       strace-log-merge-error.test \
        strace-r.test \
        strace-t.test \
        strace-tt.test \
diff --git a/tests/strace-log-merge-error.test b/tests/strace-log-merge-error.test
new file mode 100755 (executable)
index 0000000..35a2de8
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# Check strace-log-merge error diagnostics.
+#
+# Copyright (c) 2019 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+. "${srcdir=.}/init.sh"
+
+rm -f -- "$LOG".[0-9]*
+echo "strace-log-merge: $LOG: strace output not found" > "$EXP"
+
+check_strace_log_merge()
+{
+       "$srcdir"/../strace-log-merge "$LOG" > "$OUT" 2> "$LOG"
+       rc=$?
+
+       [ $rc -gt 0 ] ||
+               dump_log_and_fail_with 'strace-log-merge unexpectedly succeeded'
+
+       [ ! -s "$OUT" ] ||
+               dump_log_and_fail_with 'strace-log-merge unexpectedly produced output'
+
+       match_diff "$LOG" "$EXP" 'strace-log-merge error diagnostics mismatch'
+}
+
+check_strace_log_merge
+
+echo '1234567890.123456 +++ exited with 0 +++' > "$LOG".0
+check_strace_log_merge
+
+echo > "$LOG".1
+check_strace_log_merge
+
+rm -f -- "$LOG".[0-9]*