arehbein has uploaded this change for review.
WIP: ttcn3-tcpdump*.sh: Log errors to addtional file
The old output is preserved, too, in order to ensure
compatibility with expectations regarding legacy behavior.
Related: OS#5736
Change-Id: Iac919e94ee4694dea04a5c5349013c1989c90810
---
M ttcn3-tcpdump-start.sh
M ttcn3-tcpdump-stop.sh
2 files changed, 22 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/29/30129/1
diff --git a/ttcn3-tcpdump-start.sh b/ttcn3-tcpdump-start.sh
index a2dc21f..425a432 100755
--- a/ttcn3-tcpdump-start.sh
+++ b/ttcn3-tcpdump-start.sh
@@ -71,9 +71,28 @@
PID=$!
echo $PID > $PIDFILE_NETCAT
-$CMD -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout 2>&1 &
+CMD_OUTFILE=$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout
+CMD_OUTFILE_ERR=$TTCN3_PCAP_PATH/$TESTCASE.pcap_err
+FIFO=/tmp/cmderr
+if ! [ -e $FIFO ]; then
+ mkfifo $FIFO
+else
+ echo "Warning: Named pipe already exists: $FIFO"
+fi
+
+# Log stderr to CMD_OUTFILE and a dedicated error log file
+tee $CMD_OUTFILE < $FIFO > $CMD_OUTFILE_ERR &
+CMD_STR="$CMD -s 1500 -n -i any -w \"$TTCN3_PCAP_PATH/$TESTCASE.pcap\" >$CMD_OUTFILE 2>$FIFO &"
+eval $CMD_STR
+# $CMD -s 1500 -n -i any -w \"$TTCN3_PCAP_PATH/$TESTCASE.pcap\" >$CMD_OUTFILE &
PID=$!
echo $PID > $PIDFILE_PCAP
+if [ -f $CMD_OUTFILE_ERR ] && [ $(wc -l $CMD_OUTFILE_ERR | awk '{print $1}') -ne 0 ]; then
+ echo "Error running command:" >&2
+ echo " $CMD_STR" >&2
+ echo "Error message:" >&2
+ echo " $(cat $CMD_OUTFILE_ERR)" >&2
+fi
# Wait until packet dumper creates the pcap file and starts recording.
# We generate some traffic until we see packet dumper catches it.
diff --git a/ttcn3-tcpdump-stop.sh b/ttcn3-tcpdump-stop.sh
index 7927e9c..2ddae71 100755
--- a/ttcn3-tcpdump-stop.sh
+++ b/ttcn3-tcpdump-stop.sh
@@ -68,5 +68,7 @@
kill_rm_pidfile "$PIDFILE_PCAP"
kill_rm_pidfile "$PIDFILE_NETCAT"
+FIFO=cmderr
+rm $FIFO
gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap"
To view, visit change 30129. To unsubscribe, or for help writing mail filters, visit settings.