Commit 5f147476 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'selftests-pmtu-sh-fix-cleanup-of-processes-launched-in-subshell'

Guillaume Nault says:

====================
selftests: pmtu.sh: Fix cleanup of processes launched in subshell.

Depending on the options used, pmtu.sh may launch tcpdump and nettest
processes in the background. However it fails to clean them up after
the tests complete.

Patch 1 allows the cleanup() function to read the list of PIDs launched
by the tests.
Patch 2 fixes the way the nettest PIDs are retrieved.
====================

Link: https://lore.kernel.org/r/cover.1646776561.git.gnault@redhat.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents f80cfe2f 94a4a4fe
Loading
Loading
Loading
Loading
+17 −4
Original line number Original line Diff line number Diff line
@@ -374,6 +374,16 @@ run_cmd() {
	return $rc
	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
# Find the auto-generated name for this namespace
nsname() {
nsname() {
	eval echo \$NS_$1
	eval echo \$NS_$1
@@ -670,10 +680,10 @@ setup_nettest_xfrm() {
	[ ${1} -eq 6 ] && proto="-6" || proto=""
	[ ${1} -eq 6 ] && proto="-6" || proto=""
	port=${2}
	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} $!"
	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} $!"
	nettest_pids="${nettest_pids} $!"
}
}


@@ -865,7 +875,6 @@ setup_ovs_bridge() {
setup() {
setup() {
	[ "$(id -u)" -ne 0 ] && echo "  need to run as root" && return $ksft_skip
	[ "$(id -u)" -ne 0 ] && echo "  need to run as root" && return $ksft_skip


	cleanup
	for arg do
	for arg do
		eval setup_${arg} || { echo "  ${arg} not supported"; return 1; }
		eval setup_${arg} || { echo "  ${arg} not supported"; return 1; }
	done
	done
@@ -876,7 +885,7 @@ trace() {


	for arg do
	for arg do
		[ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue
		[ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue
		${ns_cmd} tcpdump -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null &
		${ns_cmd} tcpdump --immediate-mode -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null &
		tcpdump_pids="${tcpdump_pids} $!"
		tcpdump_pids="${tcpdump_pids} $!"
		ns_cmd=
		ns_cmd=
	done
	done
@@ -1836,6 +1845,10 @@ run_test() {


	unset IFS
	unset IFS


	# Since cleanup() relies on variables modified by this subshell, it
	# has to run in this context.
	trap cleanup EXIT

	if [ "$VERBOSE" = "1" ]; then
	if [ "$VERBOSE" = "1" ]; then
		printf "\n##########################################################################\n\n"
		printf "\n##########################################################################\n\n"
	fi
	fi