Author: bdrewery
Date: Fri Jan 29 00:44:32 2016
New Revision: 295027
URL: https://svnweb.freebsd.org/changeset/base/295027

Log:
  filemon: Track the process pointer rather than a pid.
  
  The process is not held since the process_exit hook is called after the
  exithold.  There is no need to hold the process since the hook will
  always see it exiting via the process_exit event.
  
  MFC after:    2 weeks
  Sponsored by: EMC / Isilon Storage Division

Modified:
  head/sys/dev/filemon/filemon.c
  head/sys/dev/filemon/filemon_wrapper.c

Modified: head/sys/dev/filemon/filemon.c
==============================================================================
--- head/sys/dev/filemon/filemon.c      Fri Jan 29 00:44:28 2016        
(r295026)
+++ head/sys/dev/filemon/filemon.c      Fri Jan 29 00:44:32 2016        
(r295027)
@@ -89,7 +89,7 @@ struct filemon {
        TAILQ_ENTRY(filemon) link;      /* Link into the in-use list. */
        struct sx       lock;           /* Lock mutex for this filemon. */
        struct file     *fp;            /* Output file pointer. */
-       pid_t           pid;            /* The process ID being monitored. */
+       struct proc     *p;             /* The process being monitored. */
        char            fname1[MAXPATHLEN]; /* Temporary filename buffer. */
        char            fname2[MAXPATHLEN]; /* Temporary filename buffer. */
        char            msgbufr[1024];  /* Output message buffer. */
@@ -137,7 +137,7 @@ filemon_dtr(void *data)
 
                fp = filemon->fp;
                filemon->fp = NULL;
-               filemon->pid = -1;
+               filemon->p = NULL;
 
                /* Add to the free list. */
                TAILQ_INSERT_TAIL(&filemons_free, filemon, link);
@@ -188,7 +188,7 @@ filemon_ioctl(struct cdev *dev, u_long c
                error = pget(*((pid_t *)data), PGET_CANDEBUG | PGET_NOTWEXIT,
                    &p);
                if (error == 0) {
-                       filemon->pid = p->p_pid;
+                       filemon->p = p;
                        PROC_UNLOCK(p);
                }
                break;
@@ -221,7 +221,6 @@ filemon_open(struct cdev *dev, int oflag
                filemon = malloc(sizeof(struct filemon), M_FILEMON,
                    M_WAITOK | M_ZERO);
                sx_init(&filemon->lock, "filemon");
-               filemon->pid = -1;
        }
 
        devfs_set_cdevpriv(filemon, filemon_dtr);

Modified: head/sys/dev/filemon/filemon_wrapper.c
==============================================================================
--- head/sys/dev/filemon/filemon_wrapper.c      Fri Jan 29 00:44:28 2016        
(r295026)
+++ head/sys/dev/filemon/filemon_wrapper.c      Fri Jan 29 00:44:32 2016        
(r295027)
@@ -98,7 +98,7 @@ filemon_pid_check(struct proc *p)
        sx_slock(&proctree_lock);
        while (p != initproc) {
                TAILQ_FOREACH(filemon, &filemons_inuse, link) {
-                       if (p->p_pid == filemon->pid) {
+                       if (p == filemon->p) {
                                sx_sunlock(&proctree_lock);
                                filemon_filemon_lock(filemon);
                                filemon_unlock_read();
@@ -452,14 +452,14 @@ filemon_event_process_exit(void *arg __u
                filemon_output(filemon, filemon->msgbufr, len);
 
                /* Check if the monitored process is about to exit. */
-               if (filemon->pid == p->p_pid) {
+               if (filemon->p == p) {
                        len = snprintf(filemon->msgbufr,
                            sizeof(filemon->msgbufr),
                            "# Stop %ju.%06ju\n# Bye bye\n",
                            (uintmax_t)now.tv_sec, (uintmax_t)now.tv_usec);
 
                        filemon_output(filemon, filemon->msgbufr, len);
-                       filemon->pid = -1;
+                       filemon->p = NULL;
                }
 
                /* Unlock the found filemon structure. */
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to