jobs: Fix waitcmd busy loop
diff mbox series

Message ID 20200602134648.GA17275@gondor.apana.org.au
State Accepted
Delegated to: Herbert Xu
Headers show
Series
  • jobs: Fix waitcmd busy loop
Related show

Commit Message

Herbert Xu June 2, 2020, 1:46 p.m. UTC
We need to clear gotsigchld in waitproc because it is used as
a loop conditional for the waitcmd case.  Without it waitcmd
may busy loop after a SIGCHLD.

This patch also changes gotsigchld into a volatile sig_atomic_t
to prevent compilers from optimising its accesses away.

Fixes: 6c691b3e5099 ("jobs: Only clear gotsigchld when waiting...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Patch
diff mbox series

diff --git a/src/jobs.c b/src/jobs.c
index 94bf47e..3417633 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -1135,7 +1135,6 @@  static int dowait(int block, struct job *jp)
 	rpid = 1;
 
 	do {
-		gotsigchld = 0;
 		pid = waitone(block, jp);
 		rpid &= !!pid;
 
@@ -1175,6 +1174,7 @@  waitproc(int block, int *status)
 #endif
 
 	do {
+		gotsigchld = 0;
 		do
 			err = wait3(status, flags, NULL);
 		while (err < 0 && errno == EINTR);
diff --git a/src/trap.c b/src/trap.c
index 82e7ece..cd84814 100644
--- a/src/trap.c
+++ b/src/trap.c
@@ -76,7 +76,7 @@  static char gotsig[NSIG - 1];
 /* last pending signal */
 volatile sig_atomic_t pending_sig;
 /* received SIGCHLD */
-int gotsigchld;
+volatile sig_atomic_t gotsigchld;
 
 extern char *signal_names[];
 
diff --git a/src/trap.h b/src/trap.h
index 4c455a8..beaf660 100644
--- a/src/trap.h
+++ b/src/trap.h
@@ -39,7 +39,7 @@ 
 extern int trapcnt;
 extern char sigmode[];
 extern volatile sig_atomic_t pending_sig;
-extern int gotsigchld;
+extern volatile sig_atomic_t gotsigchld;
 
 int trapcmd(int, char **);
 void setsignal(int);