Tue Oct 13 00:27:19 2015 UTC ()
Currently, if a process is exiting and its parent has indicated no intent
of reaping the process (nor any other children), the process wil get
reparented to init.  Since the state of the exiting process at this point
is SDEAD, proc_reparent() will not update either the old or new parent's
p_nstopchild counters.

This change causes both old and new parents to be properly updated.

Fixes PR kern/50300

Pullups will be requested for:

       NetBSD-7, -6, -6-0, -6-1, -5, -5-0, -5-1, and -5-2


(pgoyette)
diff -r1.245 -r1.246 src/sys/kern/kern_exit.c

cvs diff -r1.245 -r1.246 src/sys/kern/kern_exit.c (expand / switch to unified diff)

--- src/sys/kern/kern_exit.c 2015/10/02 16:54:15 1.245
+++ src/sys/kern/kern_exit.c 2015/10/13 00:27:19 1.246
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_exit.c,v 1.245 2015/10/02 16:54:15 christos Exp $ */ 1/* $NetBSD: kern_exit.c,v 1.246 2015/10/13 00:27:19 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and by Andrew Doran. 9 * NASA Ames Research Center, and by Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -57,27 +57,27 @@ @@ -57,27 +57,27 @@
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE. 64 * SUCH DAMAGE.
65 * 65 *
66 * @(#)kern_exit.c 8.10 (Berkeley) 2/23/95 66 * @(#)kern_exit.c 8.10 (Berkeley) 2/23/95
67 */ 67 */
68 68
69#include <sys/cdefs.h> 69#include <sys/cdefs.h>
70__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.245 2015/10/02 16:54:15 christos Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.246 2015/10/13 00:27:19 pgoyette Exp $");
71 71
72#include "opt_ktrace.h" 72#include "opt_ktrace.h"
73#include "opt_dtrace.h" 73#include "opt_dtrace.h"
74#include "opt_perfctrs.h" 74#include "opt_perfctrs.h"
75#include "opt_sysv.h" 75#include "opt_sysv.h"
76 76
77#include <sys/param.h> 77#include <sys/param.h>
78#include <sys/systm.h> 78#include <sys/systm.h>
79#include <sys/ioctl.h> 79#include <sys/ioctl.h>
80#include <sys/tty.h> 80#include <sys/tty.h>
81#include <sys/time.h> 81#include <sys/time.h>
82#include <sys/resource.h> 82#include <sys/resource.h>
83#include <sys/kernel.h> 83#include <sys/kernel.h>
@@ -949,26 +949,26 @@ proc_free(struct proc *p, struct rusage  @@ -949,26 +949,26 @@ proc_free(struct proc *p, struct rusage
949 * make process 'parent' the new parent of process 'child'. 949 * make process 'parent' the new parent of process 'child'.
950 * 950 *
951 * Must be called with proc_lock held. 951 * Must be called with proc_lock held.
952 */ 952 */
953void 953void
954proc_reparent(struct proc *child, struct proc *parent) 954proc_reparent(struct proc *child, struct proc *parent)
955{ 955{
956 956
957 KASSERT(mutex_owned(proc_lock)); 957 KASSERT(mutex_owned(proc_lock));
958 958
959 if (child->p_pptr == parent) 959 if (child->p_pptr == parent)
960 return; 960 return;
961 961
962 if (child->p_stat == SZOMB || 962 if (child->p_stat == SZOMB || child->p_stat == SDEAD ||
963 (child->p_stat == SSTOP && !child->p_waited)) { 963 (child->p_stat == SSTOP && !child->p_waited)) {
964 child->p_pptr->p_nstopchild--; 964 child->p_pptr->p_nstopchild--;
965 parent->p_nstopchild++; 965 parent->p_nstopchild++;
966 } 966 }
967 if (parent == initproc) 967 if (parent == initproc)
968 child->p_exitsig = SIGCHLD; 968 child->p_exitsig = SIGCHLD;
969 969
970 LIST_REMOVE(child, p_sibling); 970 LIST_REMOVE(child, p_sibling);
971 LIST_INSERT_HEAD(&parent->p_children, child, p_sibling); 971 LIST_INSERT_HEAD(&parent->p_children, child, p_sibling);
972 child->p_pptr = parent; 972 child->p_pptr = parent;
973 child->p_ppid = parent->p_pid; 973 child->p_ppid = parent->p_pid;
974} 974}