Source-Changes-HG archive

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

[src/trunk]: src/sys/kern PR/51624: Return the original parent for a traced p...



details:   https://anonhg.NetBSD.org/src/rev/cf2ea854f119
branches:  trunk
changeset: 348872:cf2ea854f119
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Nov 12 19:42:47 2016 +0000

description:
PR/51624: Return the original parent for a traced process.

diffstat:

 sys/kern/kern_prot.c |  25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)

diffs (60 lines):

diff -r d918ad38b4ff -r cf2ea854f119 sys/kern/kern_prot.c
--- a/sys/kern/kern_prot.c      Sat Nov 12 16:33:48 2016 +0000
+++ b/sys/kern/kern_prot.c      Sat Nov 12 19:42:47 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_prot.c,v 1.119 2015/08/24 22:50:32 pooka Exp $    */
+/*     $NetBSD: kern_prot.c,v 1.120 2016/11/12 19:42:47 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.119 2015/08/24 22:50:32 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_prot.c,v 1.120 2016/11/12 19:42:47 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_43.h"
@@ -80,6 +80,21 @@
        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)
@@ -87,7 +102,7 @@
        struct proc *p = l->l_proc;
 
        retval[0] = p->p_pid;
-       retval[1] = p->p_ppid;
+       retval[1] = kern_getppid(l);
        return (0);
 }
 
@@ -95,9 +110,7 @@
 int
 sys_getppid(struct lwp *l, const void *v, register_t *retval)
 {
-       struct proc *p = l->l_proc;
-
-       *retval = p->p_ppid;
+       *retval = kern_getppid(l);
        return (0);
 }
 



Home | Main Index | Thread Index | Old Index