Subject: Inheritance of P_CLDSIGIGN
To: None <tech-kern@netbsd.org>
From: Quentin Garnier <cube@cubidou.net>
List: tech-kern
Date: 05/17/2005 12:00:47
--Chn8nxio6L/4biUD
Content-Type: multipart/mixed; boundary="SSJ6yXlPvEk0CmSI"
Content-Disposition: inline


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

Hi,

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>

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

	if (fork()) {
		_exit(0);
	}
	if (fork()) {
		sleep(15);
		_exit(1);
	}
	_exit(2);
}

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}.

Comments?

--=20
Quentin Garnier - cube@cubidou.net - cube@NetBSD.org
"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.

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

Index: kern_fork.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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=
IGN);
 	p2->p_emul =3D p1->p_emul;
 	p2->p_execsw =3D p1->p_execsw;
=20

--SSJ6yXlPvEk0CmSI--

--Chn8nxio6L/4biUD
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (NetBSD)

iQEVAwUBQonAz9goQloHrPnoAQJ7EQf/ZWA3OQ1g9eiKN0LXTTj5ArBabqAw9/vt
LRKz9LCt8MNRfCy1nC1H04+jEfALFwlIlQ2KhfWqAX2WNGRxQ+hyUoup5EJGNIJp
oiW1sLpkRFOCu4EanyLijS6M6/Dx+G5fLn7uNH9vaGv+ul4TnJGM9mfpUtsRljT3
/hhJVtwdph/JDkILeauw6ooZp7FtP3UC8FxIthwHIHADgec1KFsfOE6djPTRLH5K
ypH9B7iPt1j6Atslnrp9a7yHP+RMkD2MlA34dz38iQr5Gnp4LgTYyps9UNdcJWw6
ln0h2NtknRG3w4779DUSVYB/AY6DC8xakLniD0I9Biw3NVT7N6xLgw==
=x3L8
-----END PGP SIGNATURE-----

--Chn8nxio6L/4biUD--