From owner-svn-src-head@FreeBSD.ORG Sun Aug 24 09:04:10 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 37EEF122; Sun, 24 Aug 2014 09:04:10 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0A1CE37F5; Sun, 24 Aug 2014 09:04:10 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7O949Oc083662; Sun, 24 Aug 2014 09:04:09 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s7O949sI083660; Sun, 24 Aug 2014 09:04:09 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201408240904.s7O949sI083660@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sun, 24 Aug 2014 09:04:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r270444 - in head/sys: kern sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Aug 2014 09:04:10 -0000 Author: mjg Date: Sun Aug 24 09:04:09 2014 New Revision: 270444 URL: http://svnweb.freebsd.org/changeset/base/270444 Log: Fix getppid for traced processes. Traced processes always have the tracer set as the parent. Utilize proc_realparent to obtain the right process when needed. Reviewed by: kib MFC after: 1 week Modified: head/sys/kern/kern_prot.c head/sys/sys/syscallsubr.h Modified: head/sys/kern/kern_prot.c ============================================================================== --- head/sys/kern/kern_prot.c Sun Aug 24 09:02:16 2014 (r270443) +++ head/sys/kern/kern_prot.c Sun Aug 24 09:04:09 2014 (r270444) @@ -105,9 +105,7 @@ sys_getpid(struct thread *td, struct get 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); } /* Modified: head/sys/sys/syscallsubr.h ============================================================================== --- head/sys/sys/syscallsubr.h Sun Aug 24 09:02:16 2014 (r270443) +++ head/sys/sys/syscallsubr.h Sun Aug 24 09:04:09 2014 (r270444) @@ -110,6 +110,7 @@ int kern_getfsstat(struct thread *td, st 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);