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
This commit is contained in:
parent
6137c5d990
commit
d5e53f99be
@ -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 cmd, caddr_t data, int flag __unused,
|
||||
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 oflags __unused, int devtype __unused,
|
||||
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);
|
||||
|
@ -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 __unused, struct proc *p)
|
||||
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. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user