Author: bdrewery Date: Tue Mar 22 22:41:07 2016 New Revision: 297201 URL: https://svnweb.freebsd.org/changeset/base/297201
Log: Return any log write failure encountered when closing the filemon fd. Discussed with: sjg, markj Reviewed by: sjg MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Modified: head/share/man/man4/filemon.4 head/sys/dev/filemon/filemon.c head/sys/dev/filemon/filemon_wrapper.c Modified: head/share/man/man4/filemon.4 ============================================================================== --- head/share/man/man4/filemon.4 Tue Mar 22 22:41:03 2016 (r297200) +++ head/share/man/man4/filemon.4 Tue Mar 22 22:41:07 2016 (r297201) @@ -161,6 +161,12 @@ No process having the specified process The process ID specified is already being traced and was not the current process. .El +.Pp +The +.Fn close +system call on the filemon file descriptor may fail with the errors from +.Xr write 2 +if any error is encountered while writing the log. .Sh FILES .Bl -tag -width ".Pa /dev/filemon" .It Pa /dev/filemon Modified: head/sys/dev/filemon/filemon.c ============================================================================== --- head/sys/dev/filemon/filemon.c Tue Mar 22 22:41:03 2016 (r297200) +++ head/sys/dev/filemon/filemon.c Tue Mar 22 22:41:07 2016 (r297201) @@ -92,6 +92,7 @@ struct filemon { char fname1[MAXPATHLEN]; /* Temporary filename buffer. */ char fname2[MAXPATHLEN]; /* Temporary filename buffer. */ char msgbufr[1024]; /* Output message buffer. */ + int error; /* Log write error, returned on close(2). */ u_int refcnt; /* Pointer reference count. */ u_int proccnt; /* Process count. */ }; @@ -277,7 +278,10 @@ filemon_close_log(struct filemon *filemo return; } -/* The devfs file is being closed. Untrace all processes. */ +/* + * The devfs file is being closed. Untrace all processes. It is possible + * filemon_close/close(2) was not called. + */ static void filemon_dtr(void *data) { @@ -422,12 +426,28 @@ filemon_open(struct cdev *dev, int oflag return (error); } +/* Called on close of last devfs file handle, before filemon_dtr(). */ static int filemon_close(struct cdev *dev __unused, int flag __unused, int fmt __unused, struct thread *td __unused) { + struct filemon *filemon; + int error; - return (0); + if ((error = devfs_get_cdevpriv((void **) &filemon)) != 0) + return (error); + + sx_xlock(&filemon->lock); + filemon_close_log(filemon); + error = filemon->error; + sx_xunlock(&filemon->lock); + /* + * Processes are still being traced but won't log anything + * now. After this call returns filemon_dtr() is called which + * will detach processes. + */ + + return (error); } static void Modified: head/sys/dev/filemon/filemon_wrapper.c ============================================================================== --- head/sys/dev/filemon/filemon_wrapper.c Tue Mar 22 22:41:03 2016 (r297200) +++ head/sys/dev/filemon/filemon_wrapper.c Tue Mar 22 22:41:07 2016 (r297201) @@ -46,6 +46,7 @@ filemon_output(struct filemon *filemon, { struct uio auio; struct iovec aiov; + int error; if (filemon->fp == NULL) return; @@ -63,7 +64,9 @@ filemon_output(struct filemon *filemon, if (filemon->fp->f_type == DTYPE_VNODE) bwillwrite(); - fo_write(filemon->fp, &auio, curthread->td_ucred, 0, curthread); + error = fo_write(filemon->fp, &auio, curthread->td_ucred, 0, curthread); + if (error != 0) + filemon->error = error; } static int _______________________________________________ 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"