Skip to contentSkip to conversation

perf test: Don't signal all processes on system when interrupting tests

PATCH Applied James Clark 3 participants 3 messages Nov 29, 2024 – Dec 3, 2024 perf events

lore
Share & tools
lore

James Clark

author reviewer
#0 lore raw

PATCH 1/1 perf test: Don't signal all processes on system when interrupting tests

This signal handler loops over all tests on ctrl-C, but it's active while the test list is being constructed. process.pid is 0, then -1, then finally set to the child pid on fork. If the Ctrl-C is received during this point a kill(-1, SIGINT) can be sent which affects all processes.

Make sure the child has forked first before forwarding the signal. This can be reproduced with ctrl-C immediately after launching perf test which terminates the ssh connection.

Fixes 553d5efeb341 ("perf test: Add a signal handler to kill forked child processes")
---
 tools/perf/tests/builtin-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/builtin-test.c +1 -1
index 8dcf74d3c0a3..4751dd3c6f67 100644
@@ -508,7 +508,7 @@ static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
 		for (size_t x = 0; x < num_tests; x++) {
 			struct child_test *child_test = child_tests[x];
 
-			if (!child_test)
+			if (!child_test || child_test->process.pid <= 0)
 				continue;
 
 			pr_debug3("Killing %d pid %d\n",
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · James Clark

This signal handler loops over all tests on ctrl-C, but it's active while the test list is being constructed. process.pid is 0, then -1, then finally set to the child pid on fork. If the Ctrl-C is received during this point a kill(-1, SIGINT) can be sent which affects all processes.

Quoted 6 lines

Make sure the child has forked first before forwarding the signal. This can be reproduced with ctrl-C immediately after launching perf test which terminates the ssh connection.

Fixes 553d5efeb341 ("perf test: Add a signal handler to kill forked child processes")

(Resend as plain text)

Sorry for the lost ssh connections :-)

Thanks,
Ian

Quoted 21 lines
---
 tools/perf/tests/builtin-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/builtin-test.c +1 -2
index 8dcf74d3c0a3..4751dd3c6f67 100644
@@ -508,7 +508,7 @@ static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
                for (size_t x = 0; x < num_tests; x++) {
                        struct child_test *child_test = child_tests[x];
 
-                       if (!child_test)
+                       if (!child_test || child_test->process.pid <= 0)
                                continue;
 
                        pr_debug3("Killing %d pid %d\n",
--

2.34.1

maintainer Applied
#2 lore raw
In reply to James Clark
Quoted 11 lines · James Clark

This signal handler loops over all tests on ctrl-C, but it's active while the test list is being constructed. process.pid is 0, then -1, then finally set to the child pid on fork. If the Ctrl-C is received during this point a kill(-1, SIGINT) can be sent which affects all processes.

Make sure the child has forked first before forwarding the signal. This can be reproduced with ctrl-C immediately after launching perf test which terminates the ssh connection.

[...]

Applied to perf-tools, thanks!

Best regards,
Namhyung