diff options
| author | Matthieu Baerts (NGI0) <matttbe@kernel.org> | 2025-11-10 19:23:45 +0100 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2025-11-11 17:49:49 -0800 |
| commit | 852b644acbce1529307a4bb283752c4e77b5cda7 (patch) | |
| tree | de632e6a4862391d67910abe3fb771d9d64a79b1 /tools/testing/selftests/net/mptcp/mptcp_lib.sh | |
| parent | ee79980f7a428ec299f6261bea4c1084dcbc9631 (diff) | |
| download | linux-next-852b644acbce1529307a4bb283752c4e77b5cda7.tar.gz linux-next-852b644acbce1529307a4bb283752c4e77b5cda7.zip | |
selftests: mptcp: join: properly kill background tasks
The 'run_tests' function is executed in the background, but killing its
associated PID would not kill the children tasks running in the
background.
To properly kill all background tasks, 'kill -- -PID' could be used, but
this requires kill from procps-ng. Instead, all children tasks are
listed using 'ps', and 'kill' is called with all PIDs of this group.
Fixes: 31ee4ad86afd ("selftests: mptcp: join: stop transfer when check is done (part 1)")
Cc: stable@vger.kernel.org
Fixes: 04b57c9e096a ("selftests: mptcp: join: stop transfer when check is done (part 2)")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20251110-net-mptcp-sft-join-unstable-v1-6-a4332c714e10@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/testing/selftests/net/mptcp/mptcp_lib.sh')
| -rw-r--r-- | tools/testing/selftests/net/mptcp/mptcp_lib.sh | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh index d62e653d48b0..f4388900016a 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -350,6 +350,27 @@ mptcp_lib_kill_wait() { wait "${1}" 2>/dev/null } +# $1: PID +mptcp_lib_pid_list_children() { + local curr="${1}" + # evoke 'ps' only once + local pids="${2:-"$(ps o pid,ppid)"}" + + echo "${curr}" + + local pid + for pid in $(echo "${pids}" | awk "\$2 == ${curr} { print \$1 }"); do + mptcp_lib_pid_list_children "${pid}" "${pids}" + done +} + +# $1: PID +mptcp_lib_kill_group_wait() { + # Some users might not have procps-ng: cannot use "kill -- -PID" + mptcp_lib_pid_list_children "${1}" | xargs -r kill &>/dev/null + wait "${1}" 2>/dev/null +} + # $1: IP address mptcp_lib_is_v6() { [ -z "${1##*:*}" ] |
