Skip to contentSkip to conversation

selftests/proc: avoid exit() from SIGALRM handler

PATCH In review Paul Dolan 2 participants 2 messages Sep 4 – Sep 8

Subsystems (3)
lore
Share & tools
lore

Paul Dolan

author
#0 lore raw

PATCH 1/1 selftests/proc: avoid exit() from SIGALRM handler

proc-tid0 uses SIGALRM to stop the test after one second, but the signal handler calls exit(), which is not async-signal-safe.

Set a sig_atomic_t flag from the handler instead and let the main loop terminate normally. This also preserves the existing atexit cleanup that kills the worker child.

Fixes 0658a0961b0a ("procfs: do not list TID 0 in /proc/<pid>/task")
---
 tools/testing/selftests/proc/proc-tid0.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/proc/proc-tid0.c +4 -2
index 58c1d7c90a8e..79d3704b2b33 100644
@@ -25,6 +25,8 @@
 
 static pid_t pid = -1;
 
+static volatile sig_atomic_t alarmed;
+
 static void atexit_hook(void)
 {
 	if (pid > 0) {
@@ -39,7 +41,7 @@ static void *f(void *_)
 
 static void sigalrm(int _)
 {
-	exit(0);
+	alarmed = 1;
 }
 
 int main(void)
@@ -62,7 +64,7 @@ int main(void)
 		signal(SIGALRM, sigalrm);
 		alarm(1);
 
-		while (1) {
+		while (!alarmed) {
 			DIR *d = opendir(buf);
 			struct dirent *de;
 			while ((de = readdir(d))) {
Signature · 1 line
2.55.0
#1 lore raw
Quoted 9 lines · Paul Dolan

proc-tid0 uses SIGALRM to stop the test after one second, but the signal handler calls exit(), which is not async-signal-safe.

Set a sig_atomic_t flag from the handler instead and let the main loop terminate normally. This also preserves the existing atexit cleanup that kills the worker child.

Fixes 0658a0961b0a ("procfs: do not list TID 0 in /proc/<pid>/task")

Yeah, yeah.

Quoted 5 lines

static void sigalrm(int _)
{

tools/testing/selftests/proc/proc-tid0.c +1 -1
-	exit(0);
+	alarmed = 1;
 }