From owner-svn-src-all@freebsd.org Tue Mar 22 22:41:04 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AA577ADA590; Tue, 22 Mar 2016 22:41:04 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6682FDDD; Tue, 22 Mar 2016 22:41:04 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u2MMf382090025; Tue, 22 Mar 2016 22:41:03 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u2MMf3ag090024; Tue, 22 Mar 2016 22:41:03 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201603222241.u2MMf3ag090024@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Tue, 22 Mar 2016 22:41:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297200 - head/sys/dev/filemon X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Mar 2016 22:41:04 -0000 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); }