From c16954fc08cf8fd2c6b8b365fc2ee18b5eaf92a0 Mon Sep 17 00:00:00 2001 From: hrs Date: Thu, 8 Aug 2013 20:30:22 +0000 Subject: [PATCH] MFC 253887,253977: - Use pget(PGET_CANDEBUG | PGET_NOTWEXIT) to determine if the specified PID is valid for monitoring in FILEMON_SET_PID ioctl. - Set the monitored PID to -1 when the process exits. Suggested by: jilles Tested by: sjg Approved by: re (kib) git-svn-id: svn://svn.freebsd.org/base/releng/9.2@254101 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/dev/filemon/filemon.c | 8 +++++++- sys/dev/filemon/filemon_wrapper.c | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/dev/filemon/filemon.c b/sys/dev/filemon/filemon.c index 37eda433..d397c0b3 100644 --- a/sys/dev/filemon/filemon.c +++ b/sys/dev/filemon/filemon.c @@ -180,6 +180,7 @@ filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused, { int error = 0; struct filemon *filemon; + struct proc *p; #if __FreeBSD_version < 701000 filemon = dev->si_drv1; @@ -202,7 +203,12 @@ filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused, /* Set the monitored process ID. */ case FILEMON_SET_PID: - filemon->pid = *((pid_t *) data); + error = pget(*((pid_t *)data), PGET_CANDEBUG | PGET_NOTWEXIT, + &p); + if (error == 0) { + filemon->pid = p->p_pid; + PROC_UNLOCK(p); + } break; default: diff --git a/sys/dev/filemon/filemon_wrapper.c b/sys/dev/filemon/filemon_wrapper.c index 2c358e4e..edbb43f2 100644 --- a/sys/dev/filemon/filemon_wrapper.c +++ b/sys/dev/filemon/filemon_wrapper.c @@ -574,6 +574,7 @@ filemon_wrapper_sys_exit(struct thread *td, struct sys_exit_args *uap) (uintmax_t)now.tv_sec, (uintmax_t)now.tv_usec); filemon_output(filemon, filemon->msgbufr, len); + filemon->pid = -1; } /* Unlock the found filemon structure. */ -- 2.42.0