Module Name:    xsrc
Committed By:   mlelstv
Date:           Fri Oct 20 10:18:56 UTC 2023

Modified Files:
        xsrc/external/mit/ctwm/dist: signals.c

Log Message:
Use a SIGCHLD handler instead of ignoring the signal.

This avoids lockups when child processes were inherited (e.g. from .xsession)
but new children are waited for in system().


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 xsrc/external/mit/ctwm/dist/signals.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/external/mit/ctwm/dist/signals.c
diff -u xsrc/external/mit/ctwm/dist/signals.c:1.1.1.1 xsrc/external/mit/ctwm/dist/signals.c:1.2
--- xsrc/external/mit/ctwm/dist/signals.c:1.1.1.1	Wed Jul  5 07:36:07 2023
+++ xsrc/external/mit/ctwm/dist/signals.c	Fri Oct 20 10:18:55 2023
@@ -8,6 +8,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <errno.h>
+#include <sys/wait.h>
 
 #include "ctwm_shutdown.h"
 #include "signals.h"
@@ -26,6 +28,15 @@ static bool sig_shutdown = false;
 // needs to trigger an action.
 bool SignalFlag = false;
 
+void ChildExit(int signum)
+{
+	int Errno = errno;
+	/* reap dead children, ignore status */
+	while (waitpid(-1, NULL, WNOHANG) > 0)
+		continue;
+	/* restore errno for interrupted sys calls */
+	errno = Errno;
+}
 
 /**
  * Setup signal handlers (run during startup)
@@ -46,9 +57,12 @@ setup_signal_handlers(void)
 	// die...
 	signal(SIGALRM, SIG_IGN);
 
-	// This should be set by default, but just in case; explicitly don't
-	// leave zombies.
-	signal(SIGCHLD, SIG_IGN);
+	/* Setting SIGCHLD to SIG_IGN detaches children from the parent
+	 * immediately, so it need not be waited for.
+	 * In fact, you cannot wait for it, so a function like system()
+	 * breaks.
+	 */
+	signal(SIGCHLD, ChildExit);
 
 	return;
 }

Reply via email to