Change in osmo-ttcn3-hacks[master]: Generalize ttcn3-tcpdump-*.sh

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Thu Mar 14 20:46:51 UTC 2019


Max has submitted this change and it was merged. ( https://gerrit.osmocom.org/13252 )

Change subject: Generalize ttcn3-tcpdump-*.sh
......................................................................

Generalize ttcn3-tcpdump-*.sh

Prepare for supporting alternative packet dumpers:
* reword comments
* rename pidfile
* move tcpdump-specific option inside if
* move comment about sudo closer to actual sudo invocation

Those are cosmetic changes which do not affect how packet dump is made
but makes it easier to support alternative packet dumpers in follow-up
commit.

Change-Id: Ib2528db65348c0422fe8b7c7c53656fbce4f6405
---
M ttcn3-tcpdump-start.sh
M ttcn3-tcpdump-stop.sh
2 files changed, 14 insertions(+), 14 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/ttcn3-tcpdump-start.sh b/ttcn3-tcpdump-start.sh
index 747002b..b8ad01a 100755
--- a/ttcn3-tcpdump-start.sh
+++ b/ttcn3-tcpdump-start.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-PIDFILE=/tmp/tcpdump.pid
+PIDFILE=/tmp/dumper.pid
 TCPDUMP=/usr/sbin/tcpdump
 TESTCASE=$1
 
@@ -16,19 +16,19 @@
 	rm $PIDFILE
 fi
 
+if [ "$(id -u)" = "0" ]; then
+	CMD="$TCPDUMP -U"
+else
 # NOTE: This requires you to be root or something like
 # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
-if [ "$(id -u)" = "0" ]; then
-	CMD=$TCPDUMP
-else
-	CMD="sudo $TCPDUMP"
+	CMD="sudo $TCPDUMP -U"
 fi
-$CMD -U -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout 2>&1 &
+$CMD -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout 2>&1 &
 PID=$!
 echo $PID > $PIDFILE
 
-# Wait until tcpdump creates the pcap file and starts recording.
-# We generate some traffic until we see tcpdump catches it.
+# Wait until packet dumper creates the pcap file and starts recording.
+# We generate some traffic until we see packet dumper catches it.
 # Timeout is 10 seconds.
 ping 127.0.0.1 >/dev/null 2>&1 &
 PID=$!
@@ -36,7 +36,7 @@
 while [ ! -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap" ] ||
       [ "$(stat -c '%s' "$TTCN3_PCAP_PATH/$TESTCASE.pcap")" -eq 32 ]
 do
-	echo "Waiting for tcpdump to start... $i"
+	echo "Waiting for packet dumper to start... $i"
 	sleep 1
 	i=$((i+1))
 	if [ $i -eq 10 ]; then
diff --git a/ttcn3-tcpdump-stop.sh b/ttcn3-tcpdump-stop.sh
index baabefe..f53cf5d 100755
--- a/ttcn3-tcpdump-stop.sh
+++ b/ttcn3-tcpdump-stop.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-PIDFILE=/tmp/tcpdump.pid
+PIDFILE=/tmp/dumper.pid
 TESTCASE=$1
 VERDICT="$2"
 
@@ -17,14 +17,14 @@
 	TTCN3_PCAP_PATH=/tmp
 fi
 
-# Wait for up to 2 seconds if we keep receiving traffinc from tcpdump,
+# Wait for up to 2 seconds if we keep receiving traffinc from packet dumper,
 # otherwise we might lose last packets from test.
 i=0
 prev_count=-1
 count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
 while [ $count -gt $prev_count ] && [ $i -lt 2 ]
 do
-	echo "Waiting for tcpdump to finish... $i (prev_count=$prev_count, count=$count)"
+	echo "Waiting for packet dumper to finish... $i (prev_count=$prev_count, count=$count)"
 	sleep 1
 	prev_count=$count
 	count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap")
@@ -32,11 +32,11 @@
 done
 
 if [ -e $PIDFILE ]; then
-	# NOTE: This requires you to be root or something like
-	# "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
 	if [ "$(id -u)" = "0" ]; then
 		kill "$(cat "$PIDFILE")"
 	else
+	# NOTE: This requires you to be root or something like
+	# "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
 		sudo kill "$(cat "$PIDFILE")"
 	fi
 	rm $PIDFILE

-- 
To view, visit https://gerrit.osmocom.org/13252
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib2528db65348c0422fe8b7c7c53656fbce4f6405
Gerrit-Change-Number: 13252
Gerrit-PatchSet: 2
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Daniel Willmann <dwillmann at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190314/aed6e7b0/attachment.htm>


More information about the gerrit-log mailing list