ttcn3-tcpdump*.sh: Fix scripts hanging on sudo prompt
Related: OS#5736 Change-Id: I05687f9bc0bb87c6f1d5c42ba235dbb90a49aeb6
This commit is contained in:
parent
94e60c851c
commit
cf8c450ed5
|
@ -10,9 +10,19 @@ GSMTAP_PORT=4729
|
||||||
|
|
||||||
TESTCASE=$1
|
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() {
|
kill_rm_pidfile() {
|
||||||
if [ -e $1 ]; then
|
# NOTE: This requires you to be root or something like
|
||||||
kill "$(cat "$1")"
|
# "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
|
rm $1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -27,13 +37,7 @@ fi
|
||||||
kill_rm_pidfile $PIDFILE_NETCAT
|
kill_rm_pidfile $PIDFILE_NETCAT
|
||||||
kill_rm_pidfile $PIDFILE_PCAP
|
kill_rm_pidfile $PIDFILE_PCAP
|
||||||
|
|
||||||
if [ "$(id -u)" = "0" ]; then
|
CMD="$SUDOSTR $TCPDUMP -U"
|
||||||
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
|
|
||||||
|
|
||||||
if [ -x "$DUMPCAP" ]; then
|
if [ -x "$DUMPCAP" ]; then
|
||||||
CAP_ERR="1"
|
CAP_ERR="1"
|
||||||
|
|
|
@ -5,18 +5,20 @@ PIDFILE_NETCAT=/tmp/netcat.pid
|
||||||
TESTCASE=$1
|
TESTCASE=$1
|
||||||
VERDICT="$2"
|
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() {
|
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
|
# NOTE: This requires you to be root or something like
|
||||||
# "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
|
# "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
|
fi
|
||||||
rm $1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
date
|
date
|
||||||
|
|
Loading…
Reference in New Issue