mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-23 14:27:37 -04:00
selftests: rds: Stop tcpdump on timeout
The timeout signal handler for the rds selftests currently just exits when the time limit is exceeded, and forgets to stop the network dumps. Fix this by hoisting the tcpdump terminate commands into a helper function, and call it from the signal handler before exiting Bound proc.wait() with a timeout (and fall back to proc.kill()) so an unresponsive tcpdump cannot hang the timeout path itself. We also pop() tcpdump_procs as we iterate, so stop_pcaps() is safe to call from both the normal cleanup path and the signal handler, since the second invocation simply has nothing to do Signed-off-by: Allison Henderson <achender@kernel.org> Link: https://patch.msgid.link/20260504054143.4027538-9-achender@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
c726bc68ff
commit
ec91483634
@@ -68,11 +68,29 @@ def netns_socket(netns, *sock_args):
|
||||
u1.close()
|
||||
return socket.fromfd(fds[0], *sock_args)
|
||||
|
||||
def stop_pcaps():
|
||||
"""Stop tcpdump processes.
|
||||
|
||||
We use pop() here to drain the list in the event that the test
|
||||
completes after the signal handler is fired. List will be empty
|
||||
if logdir is not set
|
||||
"""
|
||||
print("Stopping network packet captures")
|
||||
while tcpdump_procs:
|
||||
proc = tcpdump_procs.pop()
|
||||
proc.terminate()
|
||||
try:
|
||||
proc.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
proc.kill()
|
||||
proc.wait()
|
||||
|
||||
def signal_handler(_sig, _frame):
|
||||
"""
|
||||
Test timed out signal handler
|
||||
"""
|
||||
print('Test timed out')
|
||||
stop_pcaps()
|
||||
sys.exit(1)
|
||||
|
||||
#Parse out command line arguments. We take an optional
|
||||
@@ -255,11 +273,7 @@ for s in sockets:
|
||||
|
||||
print(f"getsockopt(): {nr_success}/{nr_error}")
|
||||
|
||||
if logdir is not None:
|
||||
print("Stopping network packet captures")
|
||||
for p in tcpdump_procs:
|
||||
p.terminate()
|
||||
p.wait()
|
||||
stop_pcaps()
|
||||
|
||||
# We're done sending and receiving stuff, now let's check if what
|
||||
# we received is what we sent.
|
||||
|
||||
Reference in New Issue
Block a user