On Sat 12 Aug 2023 at 16:05:34 +0200, Rhialto wrote: > On Sat 12 Aug 2023 at 15:22:56 +0200, Rhialto wrote: > > Or, alternatively, a proper signal handler for SIGCHLD could be set up. > > I propose something like this. > It worked for me in a quick test, also when I changed the style of my > .xinitrc file from my usual > > xterm & > exec ctwm > > to > > ctwm & > exec xterm
I meant that the other way around. The bug shows in the first case.
I've also updated it slightly to save and restore errno.
=== modified file 'signals.c'
--- old/signals.c 2018-11-18 22:08:49 +0000
+++ new/signals.c 2023-08-12 15:03:42 +0000
@@ -8,6 +8,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/wait.h>
+#include <errno.h>
#include "ctwm_shutdown.h"
#include "signals.h"
@@ -16,6 +18,7 @@
/* Our backends */
static void sh_restart(int signum);
static void sh_shutdown(int signum);
+static void sh_sigchld(int signum);
// Internal flags for which signals have called us
@@ -46,9 +49,8 @@
// die...
signal(SIGALRM, SIG_IGN);
- // This should be set by default, but just in case; explicitly don't
- // leave zombies.
- signal(SIGCHLD, SIG_IGN);
+ // Explicitly don't leave zombies.
+ signal(SIGCHLD, sh_sigchld);
return;
}
@@ -123,3 +125,18 @@
SignalFlag = sig_shutdown = true;
}
+/**
+ * Handle SIGCHLD so we don't leave zombie child processes.
+ * SIG_IGN'ing it would cause system(3) to malfunction.
+ */
+static void
+sh_sigchld(int signum)
+{
+ pid_t pid;
+ int old_errno = errno;
+
+ while((pid = waitpid(-1, NULL, WNOHANG)) > 0)
+ ;
+
+ errno = old_errno;
+}
-Olaf.
--
___ Olaf 'Rhialto' Seibert <rhialto/at/falu.nl>
\X/ There is no AI. There is just someone else's work. --I. Rose
signature.asc
Description: PGP signature
