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
This commit is contained in:
Mateusz Guzik 2014-08-24 09:04:09 +00:00
parent a661bebe26
commit abd386bafe
2 changed files with 24 additions and 6 deletions

View File

@ -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);
}
@ -120,13 +118,32 @@ struct getppid_args {
/* ARGSUSED */
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);
}
/*

View File

@ -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);