coproc networkd { ./networkd "$@"; }
echo "networkd launched as PID ${networkd_PID}"
+
+ sleep 1
}
terminate_networkd() {
- if [ -n "${networkd_PID}" ]; then
- # Collect some status information
- dump_status
-
- # Send SIGTERM
- kill -TERM "${networkd_PID}"
+ local seconds=0
- # Wait until networkd has finished
- echo "Waiting for networkd to terminate..."
- wait "${networkd_PID}"
+ if [ -n "${networkd_PID}" ]; then
+ while [ -n "${networkd_PID}" ] && kill -0 "${networkd_PID}"; do
+ case "${seconds}" in
+ # Send SIGTERM in the beginning
+ 0)
+ echo "Sending SIGTERM to networkd"
+ kill -TERM "${networkd_PID}"
+ ;;
+
+ # After 5 seconds, send SIGKILL
+ 5)
+ echo "Sending SIGKILL to networkd"
+ kill -KILL "${networkd_PID}"
+
+ # It is an error, if we have to kill networkd
+ exit 1
+ ;;
+ esac
+
+ # Wait for a moment
+ sleep 1
+
+ # Increment seconds
+ (( seconds++ ))
+ done
echo "networkd has terminated"
fi
}
-# Make sure networkd has been terminated when this script exits
-trap "terminate_networkd" EXIT
-
main() {
local test="${1}"
shift
# Terminate networkd
terminate_networkd
+ # Collect some status information
+ dump_status
+
# Run cleanup script
if ! run_script "${test}/cleanup.sh"; then
return 1