Subject: Inheritance of P_CLDSIGIGN
To: None <>
From: Quentin Garnier <>
List: tech-kern
Date: 05/17/2005 12:00:47
Content-Type: multipart/mixed; boundary="SSJ6yXlPvEk0CmSI"
Content-Disposition: inline

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


While trying to understand the behaviour of a Linux program under
emulation on NetBSD, I discovered the fact that we don't inherit the
P_CLDSIGIGN flag for processes.

Consider the following program:

#include <sys/cdefs.h>
#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

main(int argc, const char *argv[])
	signal(SIGCHLD, SIG_IGN);

	if (fork()) {
	if (fork()) {

The grandchild process stays as the zombie for 15 seconds.  However,
if I read SUS correctly, this should not happen, as the fact that
SIGCHLD is ignored should be inherited (thanks Klaus for making me
read SUS right).

And actually, it is what happens!  If I add a call to signal() after
the first fork(), the return value is 0x1, i.e. SIG_IGN, which proves
that the sigaction table is correctly inherited.

What is not, however, is the P_CLDSIGIGN flag set by the first call to
signal.  Hence the grandchild stays as a zombie.

The attached patch fixes the issue, however it is not my area of
expertise, so it might not be the right place to do that.  Also, we
might want to save P_NOCLD{STOP,WAIT}.


Quentin Garnier - -
"When I find the controls, I'll go where I like, I'll know where I want
to be, but maybe for now I'll stay right here on a silent sea."
KT Tunstall, Silent Sea, Eye to the Telescope, 2004.

Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sigcld.diff"
Content-Transfer-Encoding: quoted-printable

Index: kern_fork.c
RCS file: /pub/NetBSD-CVS/src/sys/kern/kern_fork.c,v
retrieving revision 1.121
diff -u -r1.121 kern_fork.c
--- kern_fork.c	2 Mar 2005 11:05:34 -0000	1.121
+++ kern_fork.c	17 May 2005 09:52:35 -0000
@@ -294,7 +294,7 @@
 	 * The p_stats and p_sigacts substructs are set in uvm_fork().
 	 * Inherit SUGID, STOPFORK and STOPEXEC flags.
-	p2->p_flag =3D p1->p_flag & (P_SUGID | P_STOPFORK | P_STOPEXEC);
+	p2->p_flag =3D p1->p_flag & (P_SUGID | P_STOPFORK | P_STOPEXEC | P_CLDSIG=
 	p2->p_emul =3D p1->p_emul;
 	p2->p_execsw =3D p1->p_execsw;


Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.2.6 (NetBSD)