diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index f99e053..7552363 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -105,9 +105,7 @@ sys_getpid(struct thread *td, struct getpid_args *uap) td->td_retval[0] = p->p_pid; #if defined(COMPAT_43) - PROC_LOCK(p); - td->td_retval[1] = p->p_pptr->p_pid; - PROC_UNLOCK(p); + td->td_retval[1] = kern_getppid(td); #endif return (0); } @@ -121,12 +119,31 @@ struct getppid_args { int sys_getppid(struct thread *td, struct getppid_args *uap) { + + td->td_retval[0] = kern_getppid(td); + return (0); +} + +int +kern_getppid(struct thread *td) +{ struct proc *p = td->td_proc; + struct proc *pp; + int ppid; PROC_LOCK(p); - td->td_retval[0] = p->p_pptr->p_pid; - PROC_UNLOCK(p); - return (0); + if (!(p->p_flag & P_TRACED)) { + ppid = p->p_pptr->p_pid; + PROC_UNLOCK(p); + } else { + PROC_UNLOCK(p); + sx_slock(&proctree_lock); + pp = proc_realparent(p); + ppid = pp->p_pid; + sx_sunlock(&proctree_lock); + } + + return (ppid); } /* diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 2694e33..bc447ab 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -110,6 +110,7 @@ int kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize, enum uio_seg bufseg, int flags); int kern_getgroups(struct thread *td, u_int *ngrp, gid_t *groups); int kern_getitimer(struct thread *, u_int, struct itimerval *); +int kern_getppid(struct thread *); int kern_getpeername(struct thread *td, int fd, struct sockaddr **sa, socklen_t *alen); int kern_getrusage(struct thread *td, int who, struct rusage *rup);