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);
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to