Date: Tue, 22 Mar 2016 22:41:03 +0000 (UTC) From: Bryan Drewery <bdrewery@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297200 - head/sys/dev/filemon Message-ID: <201603222241.u2MMf3ag090024@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bdrewery Date: Tue Mar 22 22:41:03 2016 New Revision: 297200 URL: https://svnweb.freebsd.org/changeset/base/297200 Log: Follow-up r297156: Close the log in filemon_dtr rather than in the last reference. If the tracer has decided to the close the log then it should be fully written, not getting more entries, when close(2) returns. This was a regression in r297156 in that it allowed a traced process to continue a traced syscall and add more entries to the log while the tracer had already closed its fd or exited. This was only really part of the daemonized process case which is abnormal. MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Modified: head/sys/dev/filemon/filemon.c Modified: head/sys/dev/filemon/filemon.c ============================================================================== --- head/sys/dev/filemon/filemon.c Tue Mar 22 22:25:08 2016 (r297199) +++ head/sys/dev/filemon/filemon.c Tue Mar 22 22:41:03 2016 (r297200) @@ -109,14 +109,11 @@ filemon_acquire(struct filemon *filemon) } /* - * Release a reference and on the last one write the footer and free the - * filemon. + * Release a reference and free on the last one. */ static void filemon_release(struct filemon *filemon) { - size_t len; - struct timeval now; if (refcount_release(&filemon->refcnt) == 0) return; @@ -127,18 +124,6 @@ filemon_release(struct filemon *filemon) */ sx_assert(&filemon->lock, SA_UNLOCKED); - if (filemon->fp != NULL) { - getmicrotime(&now); - - 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); - fdrop(filemon->fp, curthread); - } - sx_destroy(&filemon->lock); free(filemon, M_FILEMON); } @@ -260,6 +245,37 @@ filemon_untrack_processes(struct filemon "attached procs still.", __func__, filemon)); } +/* + * Close out the log. + */ +static void +filemon_close_log(struct filemon *filemon) +{ + struct file *fp; + struct timeval now; + size_t len; + + sx_assert(&filemon->lock, SA_XLOCKED); + if (filemon->fp == NULL) + return; + + getmicrotime(&now); + + 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); + fp = filemon->fp; + filemon->fp = NULL; + + sx_xunlock(&filemon->lock); + fdrop(fp, curthread); + sx_xlock(&filemon->lock); + + return; +} /* The devfs file is being closed. Untrace all processes. */ static void @@ -272,11 +288,10 @@ filemon_dtr(void *data) sx_xlock(&filemon->lock); /* - * Detach the filemon. The actual closing of it may not - * occur until syscalls in other threads with references complete. - * The filemon cannot be inherited after this though. + * Detach the filemon. It cannot be inherited after this. */ filemon_untrack_processes(filemon); + filemon_close_log(filemon); filemon_drop(filemon); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201603222241.u2MMf3ag090024>