Make p_ppid contain the original parent's pid even for traced processes.

Only change it when we are being permanently reparented to init. Since
p_ppid is only used as a cached value to retrieve the parent's process id
from userland, this change makes it correct at all times. Idea from kre@
Revert specialized logic from getpid/getppid now that it is not needed.
This commit is contained in:
christos 2016-11-13 15:25:01 +00:00
parent c024434196
commit 931a19e8b1
2 changed files with 11 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_exit.c,v 1.266 2016/11/10 17:07:14 christos Exp $ */
/* $NetBSD: kern_exit.c,v 1.267 2016/11/13 15:25:01 christos Exp $ */
/*-
* Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.266 2016/11/10 17:07:14 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.267 2016/11/13 15:25:01 christos Exp $");
#include "opt_ktrace.h"
#include "opt_dtrace.h"
@ -1320,11 +1320,12 @@ proc_reparent(struct proc *child, struct proc *parent)
child->p_pptr->p_nstopchild--;
parent->p_nstopchild++;
}
if (parent == initproc)
if (parent == initproc) {
child->p_exitsig = SIGCHLD;
child->p_ppid = parent->p_pid;
}
LIST_REMOVE(child, p_sibling);
LIST_INSERT_HEAD(&parent->p_children, child, p_sibling);
child->p_pptr = parent;
child->p_ppid = parent->p_pid;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_prot.c,v 1.120 2016/11/12 19:42:47 christos Exp $ */
/* $NetBSD: kern_prot.c,v 1.121 2016/11/13 15:25:01 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1990, 1991, 1993
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_prot.c,v 1.120 2016/11/12 19:42:47 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_prot.c,v 1.121 2016/11/13 15:25:01 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_43.h"
@ -80,21 +80,6 @@ sys_getpid(struct lwp *l, const void *v, register_t *retval)
return (0);
}
static pid_t
kern_getppid(struct lwp *l)
{
struct proc *p = l->l_proc;
pid_t ppid;
mutex_enter(proc_lock);
mutex_enter(p->p_lock);
ppid = (p->p_slflag & PSL_TRACED) && p->p_opptr ? p->p_opptr->p_pid :
p->p_pptr->p_pid;
mutex_exit(p->p_lock);
mutex_exit(proc_lock);
return ppid;
}
/* ARGSUSED */
int
sys_getpid_with_ppid(struct lwp *l, const void *v, register_t *retval)
@ -102,7 +87,7 @@ sys_getpid_with_ppid(struct lwp *l, const void *v, register_t *retval)
struct proc *p = l->l_proc;
retval[0] = p->p_pid;
retval[1] = kern_getppid(l);
retval[1] = p->p_ppid;
return (0);
}
@ -110,7 +95,9 @@ sys_getpid_with_ppid(struct lwp *l, const void *v, register_t *retval)
int
sys_getppid(struct lwp *l, const void *v, register_t *retval)
{
*retval = kern_getppid(l);
struct proc *p = l->l_proc;
*retval = p->p_ppid;
return (0);
}