Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | PIDFILE=/tmp/tcpdump.pid |
Pau Espin Pedrol | dada4c5 | 2018-02-15 16:07:23 +0100 | [diff] [blame] | 4 | TESTCASE=$1 |
| 5 | |
| 6 | if [ "z$TTCN3_PCAP_PATH" = "z" ]; then |
| 7 | TTCN3_PCAP_PATH=/tmp |
| 8 | fi |
| 9 | |
| 10 | # Wait for up to 2 seconds if we keep receiving traffinc from tcpdump, |
| 11 | # otherwise we might lose last packets from test. |
| 12 | i=0 |
| 13 | prev_count=-1 |
| 14 | count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap") |
| 15 | while [ $count -gt $prev_count ] && [ $i -lt 2 ] |
| 16 | do |
| 17 | echo "Waiting for tcpdump to finish... $i (prev_count=$prev_count, count=$count)" |
| 18 | sleep 1 |
| 19 | prev_count=$count |
| 20 | count=$(stat --format="%s" "$TTCN3_PCAP_PATH/$TESTCASE.pcap") |
| 21 | i=$((i+1)) |
| 22 | done |
Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 23 | |
| 24 | if [ -e $PIDFILE ]; then |
| 25 | # NOTE: This requires you to be root or something like |
| 26 | # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file |
| 27 | if [ "$(id -u)" = "0" ]; then |
| 28 | kill "$(cat "$PIDFILE")" |
| 29 | else |
| 30 | sudo kill "$(cat "$PIDFILE")" |
| 31 | fi |
| 32 | rm $PIDFILE |
| 33 | fi |