Re: Calling system(3) when SIGCHLD is SIG_IGN'd

Rhialto <[email protected]> Sat, 12 Aug 2023 16:05:34 +0200
Newsgroups gmane.comp.window-managers.ctwm
Message-ID <[email protected]>

--vAbcgUzyfdozCZG5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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
=2Exinitrc file from my usual

    xterm &
    exec ctwm

to

    ctwm &
    exec xterm

Before the fix, the second form did indeed cause ctwm to get blocked.

=3D=3D=3D modified file 'signals.c'
--- old/signals.c	2018-11-18 22:08:49 +0000
+++ new/signals.c	2023-08-12 13:44:27 +0000
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <sys/wait.h>
=20
 #include "ctwm_shutdown.h"
 #include "signals.h"
@@ -16,6 +17,7 @@
 /* Our backends */
 static void sh_restart(int signum);
 static void sh_shutdown(int signum);
+static void sh_sigchld(int signum);
=20
=20
 // Internal flags for which signals have called us
@@ -46,9 +48,8 @@
 	// die...
 	signal(SIGALRM, SIG_IGN);
=20
-	// 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);
=20
 	return;
 }
@@ -123,3 +124,15 @@
 	SignalFlag =3D sig_shutdown =3D true;
 }
=20
+/**
+ * Handle SIGCHLD so we don't leave zombie child processes.
+ */
+static void
+sh_sigchld(int signum)
+{
+	pid_t pid;
+	int status;
+
+	while((pid =3D waitpid(-1, &status, WNOHANG)) > 0)
+		;
+}

-Olaf.
--=20
___ Olaf 'Rhialto' Seibert                            <rhialto/at/falu.nl>
\X/ There is no AI. There is just someone else's work.           --I. Rose

--vAbcgUzyfdozCZG5
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEFVAhiiWjqgwBVdQAmYnGRWHD+9MFAmTXkaoACgkQmYnGRWHD
+9Ockwf/T2uL6fAX7T/G1MwVjd0+lvs4/KgI5bQMp2N6aIz4YLOsOOsNyC+MpKbO
Ntm/Kfa+lMZby57MaDdcv8GtnGd9e8KDwQ4bm24t2Kx+MwF+dp7lGR44Ljbr41dS
ugHFoL+hI3OdQEp30yJ4SjL9NKAaXGh+OlC0kdptl+MP1Nw0dr6Lf4g5VKTQ7nfH
4AXw8Aqp6ZDtAEFyv07Y8lygfmAfoY1SNm5QlkVepupfmi5F6AfYdlvifZ+VYIoM
kEOIKgEUtJMRyk5tm0M0VPPlqoQ5oPVnZHk88NoJSSMxJu4hBbaWOtsNzlJBwVfE
Yjjfw+X0F2ypkx0w5fE1QES8bW2F9A==
=j6yF
-----END PGP SIGNATURE-----

--vAbcgUzyfdozCZG5--