Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Make p_ppid contain the original parent's pid even ...



details:   https://anonhg.NetBSD.org/src/rev/23f6f6e8a984
branches:  trunk
changeset: 819025:23f6f6e8a984
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Nov 13 15:25:01 2016 +0000

description:
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.

diffstat:

 sys/kern/kern_exit.c |   9 +++++----
 sys/kern/kern_prot.c |  25 ++++++-------------------
 2 files changed, 11 insertions(+), 23 deletions(-)

diffs (93 lines):

diff -r 021a2f14737e -r 23f6f6e8a984 sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c      Sun Nov 13 14:47:46 2016 +0000
+++ b/sys/kern/kern_exit.c      Sun Nov 13 15:25:01 2016 +0000
@@ -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 @@
                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;
 }
diff -r 021a2f14737e -r 23f6f6e8a984 sys/kern/kern_prot.c
--- a/sys/kern/kern_prot.c      Sun Nov 13 14:47:46 2016 +0000
+++ b/sys/kern/kern_prot.c      Sun Nov 13 15:25:01 2016 +0000
@@ -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 @@
        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 @@
        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 @@
 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);
 }
 



Home | Main Index | Thread Index | Old Index