]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests: mptcp: join: properly kill background tasks
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>
Mon, 10 Nov 2025 18:23:45 +0000 (19:23 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Nov 2025 09:36:05 +0000 (10:36 +0100)
commit 852b644acbce1529307a4bb283752c4e77b5cda7 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/testing/selftests/net/mptcp/mptcp_join.sh
tools/testing/selftests/net/mptcp/mptcp_lib.sh

index 4ca1e9c665dc01629f1a1b52e85cba1569207956..c2a3c88fef864a8083a18df18d148780ce769e9d 100755 (executable)
@@ -3616,7 +3616,7 @@ userspace_tests()
                chk_mptcp_info subflows 0 subflows 0
                chk_subflows_total 1 1
                kill_events_pids
-               mptcp_lib_kill_wait $tests_pid
+               mptcp_lib_kill_group_wait $tests_pid
        fi
 
        # userspace pm create destroy subflow
@@ -3644,7 +3644,7 @@ userspace_tests()
                chk_mptcp_info subflows 0 subflows 0
                chk_subflows_total 1 1
                kill_events_pids
-               mptcp_lib_kill_wait $tests_pid
+               mptcp_lib_kill_group_wait $tests_pid
        fi
 
        # userspace pm create id 0 subflow
@@ -3665,7 +3665,7 @@ userspace_tests()
                chk_mptcp_info subflows 1 subflows 1
                chk_subflows_total 2 2
                kill_events_pids
-               mptcp_lib_kill_wait $tests_pid
+               mptcp_lib_kill_group_wait $tests_pid
        fi
 
        # userspace pm remove initial subflow
@@ -3689,7 +3689,7 @@ userspace_tests()
                chk_mptcp_info subflows 1 subflows 1
                chk_subflows_total 1 1
                kill_events_pids
-               mptcp_lib_kill_wait $tests_pid
+               mptcp_lib_kill_group_wait $tests_pid
        fi
 
        # userspace pm send RM_ADDR for ID 0
@@ -3715,7 +3715,7 @@ userspace_tests()
                chk_mptcp_info subflows 1 subflows 1
                chk_subflows_total 1 1
                kill_events_pids
-               mptcp_lib_kill_wait $tests_pid
+               mptcp_lib_kill_group_wait $tests_pid
        fi
 }
 
@@ -3745,7 +3745,7 @@ endpoint_tests()
                pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
                pm_nl_check_endpoint "modif is allowed" \
                        $ns2 10.0.2.2 id 1 flags signal
-               mptcp_lib_kill_wait $tests_pid
+               mptcp_lib_kill_group_wait $tests_pid
        fi
 
        if reset_with_tcp_filter "delete and re-add" ns2 10.0.3.2 REJECT OUTPUT &&
@@ -3800,7 +3800,7 @@ endpoint_tests()
                        chk_mptcp_info subflows 3 subflows 3
                done
 
-               mptcp_lib_kill_wait $tests_pid
+               mptcp_lib_kill_group_wait $tests_pid
 
                kill_events_pids
                chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
@@ -3874,7 +3874,7 @@ endpoint_tests()
                wait_mpj $ns2
                chk_subflow_nr "after re-re-add ID 0" 3
                chk_mptcp_info subflows 3 subflows 3
-               mptcp_lib_kill_wait $tests_pid
+               mptcp_lib_kill_group_wait $tests_pid
 
                kill_events_pids
                chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
@@ -3922,7 +3922,7 @@ endpoint_tests()
                wait_mpj $ns2
                pm_nl_add_endpoint $ns1 10.0.3.1 id 2 flags signal
                wait_mpj $ns2
-               mptcp_lib_kill_wait $tests_pid
+               mptcp_lib_kill_group_wait $tests_pid
 
                join_syn_tx=3 join_connect_err=1 \
                        chk_join_nr 2 2 2
index 975d4d4c862afff2e685e86dc08a892dbd09d783..5c9acf99d041bb06a91dddfc14c28e99338ebc67 100644 (file)
@@ -327,6 +327,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##*:*}" ]