arehbein has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/30128 )


Change subject: WIP: ttcn3-tcpdump*.sh: Fix scripts hanging on sudo prompt
......................................................................

WIP: ttcn3-tcpdump*.sh: Fix scripts hanging on sudo prompt

Related: OS#5736

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



  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/28/30128/1

diff --git a/ttcn3-tcpdump-start.sh b/ttcn3-tcpdump-start.sh
index 8433c80..a2dc21f 100755
--- a/ttcn3-tcpdump-start.sh
+++ b/ttcn3-tcpdump-start.sh
@@ -10,9 +10,19 @@

 TESTCASE=$1

+
+SUDOSTR=""
+if ! [ "$(id -u)" = "0" ]; then
+       SUDOSTR="sudo -n"
+       # Otherwise, if sudo /usr/bin/kill, sudo /usr/bin/tcpdump cannot be run 
without a password prompt,
+       # and this script will hang indefinitely
+fi
+
 kill_rm_pidfile() {
-       if [ -e $1 ]; then
-               kill "$(cat "$1")"
+       # NOTE: This requires you to be root or something like
+       # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers 
file
+       if ! [ -e "$1" ] && [ -s "$1" ]; then
+               $SUDOSTR kill "$(cat "$1")" 2>&1 || grep -v "No such process"
                rm $1
        fi
 }
@@ -27,13 +37,7 @@
 kill_rm_pidfile $PIDFILE_NETCAT
 kill_rm_pidfile $PIDFILE_PCAP

-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
-       CMD="sudo $TCPDUMP -U"
-fi
+CMD="$SUDOSTR $TCPDUMP -U"

 if [ -x "$DUMPCAP" ]; then
     CAP_ERR="1"
diff --git a/ttcn3-tcpdump-stop.sh b/ttcn3-tcpdump-stop.sh
index faf5b2b..7927e9c 100755
--- a/ttcn3-tcpdump-stop.sh
+++ b/ttcn3-tcpdump-stop.sh
@@ -5,18 +5,20 @@
 TESTCASE=$1
 VERDICT="$2"

+SUDOSTR=""
+if ! [ "$(id -u)" = "0" ]; then
+       SUDOSTR="sudo -n"
+       # Otherwise, if sudo /usr/bin/kill, sudo /usr/bin/tcpdump cannot be run 
without a password prompt,
+       # and this script will hang indefinitely
+fi
+
 kill_rm_pidfile() {
-if [ -e $1 ]; then
-        PSNAME="$(ps -q "$(cat "$1")" -o comm=)"
-       if [ "$PSNAME" != "sudo" ]; then
-               kill "$(cat "$1")"
-       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 "$1")"
+       if ! [ -e "$1" ] && [ -s "$1" ]; then
+               $SUDOSTR kill "$(cat "$1")" 2>&1 || grep -v "No such process"
+               rm $1
        fi
-       rm $1
-fi
 }

 date

--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/30128
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: arehbein/wip
Gerrit-Change-Id: I088be4da30a223847455bac7f0cefc3d445fad20
Gerrit-Change-Number: 30128
Gerrit-PatchSet: 1
Gerrit-Owner: arehbein <[email protected]>
Gerrit-MessageType: newchange

Reply via email to