Author: hrs
Date: Thu Aug  8 20:30:22 2013
New Revision: 254101
URL: http://svnweb.freebsd.org/changeset/base/254101

Log:
  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)

Modified:
  releng/9.2/sys/dev/filemon/filemon.c
  releng/9.2/sys/dev/filemon/filemon_wrapper.c
Directory Properties:
  releng/9.2/sys/   (props changed)

Modified: releng/9.2/sys/dev/filemon/filemon.c
==============================================================================
--- releng/9.2/sys/dev/filemon/filemon.c        Thu Aug  8 19:30:49 2013        
(r254100)
+++ releng/9.2/sys/dev/filemon/filemon.c        Thu Aug  8 20:30:22 2013        
(r254101)
@@ -180,6 +180,7 @@ filemon_ioctl(struct cdev *dev, u_long c
 {
        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 c
 
        /* 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:

Modified: releng/9.2/sys/dev/filemon/filemon_wrapper.c
==============================================================================
--- releng/9.2/sys/dev/filemon/filemon_wrapper.c        Thu Aug  8 19:30:49 
2013        (r254100)
+++ releng/9.2/sys/dev/filemon/filemon_wrapper.c        Thu Aug  8 20:30:22 
2013        (r254101)
@@ -574,6 +574,7 @@ filemon_wrapper_sys_exit(struct thread *
                            (uintmax_t)now.tv_sec, (uintmax_t)now.tv_usec);
 
                        filemon_output(filemon, filemon->msgbufr, len);
+                       filemon->pid = -1;
                }
 
                /* Unlock the found filemon structure. */
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to