From 19af187033dafb57f0739a8b0b21f74d4e5373e8 Mon Sep 17 00:00:00 2001 From: Matthias Rampke Date: Tue, 17 Apr 2012 23:33:16 +0200 Subject: [PATCH] kill zombies if the parent set SIG_IGN on SIGCHLD fix for http://bugs.dragonflybsd.org/issues/2349 --- sys/kern/kern_exit.c | 7 ++++--- sys/kern/kern_sig.c | 8 +++++++- sys/sys/param.h | 3 ++- sys/sys/proc.h | 1 + 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index f3ffb2bea1..2a24d9db4a 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -535,10 +535,11 @@ exit1(int rv) /* * Notify parent that we're gone. If parent has the PS_NOCLDWAIT - * flag set, notify process 1 instead (and hope it will handle - * this situation). + * flag set, or if the handler is set to SIG_IGN, notify process 1 + * instead (and hope it will handle this situation). */ - if (p->p_pptr->p_sigacts->ps_flag & PS_NOCLDWAIT) { + if (p->p_pptr->p_sigacts->ps_flag & + (PS_NOCLDWAIT | PS_CLDSIGIGN)) { struct proc *pp = p->p_pptr; PHOLD(pp); diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index f3ce05c527..fd905cd9c7 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -321,6 +321,10 @@ kern_sigaction(int sig, struct sigaction *act, struct sigaction *oact) } else { p->p_sigacts->ps_flag &= ~PS_NOCLDWAIT; } + if (ps->ps_sigact[_SIG_IDX(SIGCHLD)] == SIG_IGN) + ps->ps_flag |= PS_CLDSIGIGN; + else + ps->ps_flag &= ~PS_CLDSIGIGN; } /* * Set bit in p_sigignore for signals that are set to SIG_IGN, @@ -433,7 +437,9 @@ execsigs(struct proc *p) /* * Reset no zombies if child dies flag as Solaris does. */ - p->p_sigacts->ps_flag &= ~PS_NOCLDWAIT; + p->p_sigacts->ps_flag &= ~(PS_NOCLDWAIT | PS_CLDSIGIGN); + if (ps->ps_sigact[_SIG_IDX(SIGCHLD)] == SIG_IGN) + ps->ps_sigact[_SIG_IDX(SIGCHLD)] = SIG_DFL; } /* diff --git a/sys/sys/param.h b/sys/sys/param.h index 17f8456f14..f15d0a0946 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -90,9 +90,10 @@ * 300100 - 3.1 master * 300101 - i4b (ISDN) removal * 300102 - is now just a link of + * 300103 - if SIG_IGN is set on SIGCHLD, do not keep zombie children */ #undef __DragonFly_version -#define __DragonFly_version 300102 /* propagated to newvers */ +#define __DragonFly_version 300103 /* propagated to newvers */ #include diff --git a/sys/sys/proc.h b/sys/sys/proc.h index ee829b499e..2220707e84 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -112,6 +112,7 @@ struct pgrp { #define PS_NOCLDWAIT 0x0001 /* No zombies if child dies */ #define PS_NOCLDSTOP 0x0002 /* No SIGCHLD when children stop. */ +#define PS_CLDSIGIGN 0x0004 /* The SIGCHLD handler is SIG_IGN. */ /* * pargs, used to hold a copy of the command line, if it had a sane -- 2.41.0