summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.vnet.ibm.com>2018-11-19 11:47:45 -0500
committerStefan Berger <stefanb@linux.vnet.ibm.com>2018-11-26 07:05:58 -0500
commitc53ca559180a79a3b831246dd73c4e9a5468199b (patch)
tree0643d39df8028917d9c4fe0b415649155f5ffdc0
parentf770f31b1b6b4541664c486cac356f346444fc70 (diff)
downloadgnutls-c53ca559180a79a3b831246dd73c4e9a5468199b.tar.gz
tests: tpm: Use kill_proc to terminate a process
Use kill_proc to terminate a process by first sending it SIGTERM, waiting max. 1 second and then use SIGKILL. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
-rw-r--r--tests/scripts/common.sh21
-rwxr-xr-xtests/tpmtool_test.sh4
2 files changed, 22 insertions, 3 deletions
diff --git a/tests/scripts/common.sh b/tests/scripts/common.sh
index 94333f19b3..1567d8e614 100644
--- a/tests/scripts/common.sh
+++ b/tests/scripts/common.sh
@@ -238,6 +238,25 @@ kill_quiet() {
local sig="$1"
local pid="$2"
- sh -c "kill $sig $pid &>/dev/null"
+ sh -c "kill $sig $pid 2>/dev/null"
return $?
}
+
+# Terminate a process first using SIGTERM, wait 1s and if still avive use
+# SIGKILL
+# @1: pid
+terminate_proc() {
+ local pid="$1"
+
+ local ctr=0
+
+ kill_quiet -15 $pid
+ while [ $ctr -lt 10 ]; do
+ sleep 0.1
+ kill -0 $pid 2>/dev/null
+ [ $? -ne 0 ] && return
+ ctr=$((ctr + 1))
+ done
+ kill_quiet -9 $pid
+ sleep 0.1
+}
diff --git a/tests/tpmtool_test.sh b/tests/tpmtool_test.sh
index 978727ca37..c6e4bc42ef 100755
--- a/tests/tpmtool_test.sh
+++ b/tests/tpmtool_test.sh
@@ -126,7 +126,7 @@ start_swtpm()
stop_swtpm()
{
if [ -n "$SWTPM_PID" ]; then
- kill_quiet -15 $SWTPM_PID
+ terminate_proc $SWTPM_PID
unset SWTPM_PID
fi
}
@@ -165,7 +165,7 @@ _EOF_
stop_tcsd()
{
if [ -n "$TCSD_PID" ]; then
- kill_quiet -15 $TCSD_PID
+ terminate_proc $TCSD_PID
unset TCSD_PID
fi
stop_swtpm