selftests: pmtu.sh: Kill nettest processes launched in subshell.

When using "run_cmd <command> &", then "$!" refers to the PID of the
subshell used to run <command>, not the command itself. Therefore
nettest_pids actually doesn't contain the list of the nettest commands
running in the background. So cleanup() can't kill them and the nettest
processes run until completion (fortunately they have a 5s timeout).

Fix this by defining a new command for running processes in the
background, for which "$!" really refers to the PID of the command run.

Also, double quote variables on the modified lines, to avoid shellcheck
warnings.

Fixes: ece1278a9b ("selftests: net: add ESP-in-UDP PMTU test")
Signed-off-by: Guillaume Nault <gnault@redhat.com>
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Guillaume Nault 2022-03-08 23:15:03 +01:00 committed by Jakub Kicinski
parent 18dfc66755
commit 94a4a4fe4c

View file

@ -374,6 +374,16 @@ run_cmd() {
return $rc
}
run_cmd_bg() {
cmd="$*"
if [ "$VERBOSE" = "1" ]; then
printf " COMMAND: %s &\n" "${cmd}"
fi
$cmd 2>&1 &
}
# Find the auto-generated name for this namespace
nsname() {
eval echo \$NS_$1
@ -670,10 +680,10 @@ setup_nettest_xfrm() {
[ ${1} -eq 6 ] && proto="-6" || proto=""
port=${2}
run_cmd ${ns_a} nettest ${proto} -q -D -s -x -p ${port} -t 5 &
run_cmd_bg "${ns_a}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5
nettest_pids="${nettest_pids} $!"
run_cmd ${ns_b} nettest ${proto} -q -D -s -x -p ${port} -t 5 &
run_cmd_bg "${ns_b}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5
nettest_pids="${nettest_pids} $!"
}