From owner-svn-src-all@freebsd.org Fri Jul 3 20:43:32 2015 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 D660499343B; Fri, 3 Jul 2015 20:43:32 +0000 (UTC) (envelope-from sjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::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 C6C052E92; Fri, 3 Jul 2015 20:43:32 +0000 (UTC) (envelope-from sjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t63KhWP4034364; Fri, 3 Jul 2015 20:43:32 GMT (envelope-from sjg@FreeBSD.org) Received: (from sjg@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t63KhWWK034362; Fri, 3 Jul 2015 20:43:32 GMT (envelope-from sjg@FreeBSD.org) Message-Id: <201507032043.t63KhWWK034362@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sjg set sender to sjg@FreeBSD.org using -f From: "Simon J. Gerraty" Date: Fri, 3 Jul 2015 20:43:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r285112 - stable/10/sys/dev/filemon X-SVN-Group: stable-10 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.20 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: Fri, 03 Jul 2015 20:43:33 -0000 Author: sjg Date: Fri Jul 3 20:43:31 2015 New Revision: 285112 URL: https://svnweb.freebsd.org/changeset/base/285112 Log: Latest clang uses openat(2). If the pathname is absolute or dirfd is AT_FDCWD we can handle it exactly like open(2). Otherwise we output an A record to indicate that the path of an open directory needs to be used (earlier in the trace). Also filemon_pid_check needs to hold proctree_lock and use proc_realparent() Differential Revision: D2810 Reviewed by: jhb Approved by: re Modified: stable/10/sys/dev/filemon/filemon.h stable/10/sys/dev/filemon/filemon_wrapper.c Modified: stable/10/sys/dev/filemon/filemon.h ============================================================================== --- stable/10/sys/dev/filemon/filemon.h Fri Jul 3 20:42:31 2015 (r285111) +++ stable/10/sys/dev/filemon/filemon.h Fri Jul 3 20:43:31 2015 (r285112) @@ -30,5 +30,5 @@ #define FILEMON_SET_FD _IOWR('S', 1, int) #define FILEMON_SET_PID _IOWR('S', 2, pid_t) -#define FILEMON_VERSION 4 /* output format +#define FILEMON_VERSION 5 /* output format (bump when adding record types) */ Modified: stable/10/sys/dev/filemon/filemon_wrapper.c ============================================================================== --- stable/10/sys/dev/filemon/filemon_wrapper.c Fri Jul 3 20:42:31 2015 (r285111) +++ stable/10/sys/dev/filemon/filemon_wrapper.c Fri Jul 3 20:43:31 2015 (r285112) @@ -28,6 +28,8 @@ #include __FBSDID("$FreeBSD$"); +#include + #include "opt_compat.h" #if __FreeBSD_version > 800032 @@ -84,13 +86,17 @@ filemon_pid_check(struct proc *p) { struct filemon *filemon; - while (p->p_pptr) { + sx_slock(&proctree_lock); + while (p != initproc) { TAILQ_FOREACH(filemon, &filemons_inuse, link) { - if (p->p_pid == filemon->pid) + if (p->p_pid == filemon->pid) { + sx_sunlock(&proctree_lock); return (filemon); + } } - p = p->p_pptr; + p = proc_realparent(p); } + sx_sunlock(&proctree_lock); return (NULL); } @@ -316,6 +322,68 @@ filemon_wrapper_open(struct thread *td, } static int +filemon_wrapper_openat(struct thread *td, struct openat_args *uap) +{ + int ret; + size_t done; + size_t len; + struct filemon *filemon; + + if ((ret = sys_openat(td, uap)) == 0) { + /* Grab a read lock on the filemon inuse list. */ + filemon_lock_read(); + + if ((filemon = filemon_pid_check(curproc)) != NULL) { + /* Lock the found filemon structure. */ + filemon_filemon_lock(filemon); + + copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), &done); + + filemon->fname2[0] = '\0'; + if (filemon->fname1[0] != '/' && uap->fd != AT_FDCWD) { + /* + * rats - we cannot do too much about this. + * the trace should show a dir we read + * recently.. output an A record as a clue + * until we can do better. + */ + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), "A %d %s\n", + curproc->p_pid, filemon->fname1); + filemon_output(filemon, filemon->msgbufr, len); + } + if (uap->flag & O_RDWR) { + /* + * We'll get the W record below, but need + * to also output an R to distingish from + * O_WRONLY. + */ + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), "R %d %s%s\n", + curproc->p_pid, filemon->fname2, filemon->fname1); + filemon_output(filemon, filemon->msgbufr, len); + } + + + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), "%c %d %s%s\n", + (uap->flag & O_ACCMODE) ? 'W':'R', + curproc->p_pid, filemon->fname2, filemon->fname1); + filemon_output(filemon, filemon->msgbufr, len); + + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } + + /* Release the read lock. */ + filemon_unlock_read(); + } + + return (ret); +} + +static int filemon_wrapper_rename(struct thread *td, struct rename_args *uap) { int ret; @@ -669,6 +737,7 @@ filemon_wrapper_install(void) sv_table[SYS_execve].sy_call = (sy_call_t *) filemon_wrapper_execve; sv_table[SYS_fork].sy_call = (sy_call_t *) filemon_wrapper_fork; sv_table[SYS_open].sy_call = (sy_call_t *) filemon_wrapper_open; + sv_table[SYS_openat].sy_call = (sy_call_t *) filemon_wrapper_openat; sv_table[SYS_rename].sy_call = (sy_call_t *) filemon_wrapper_rename; sv_table[SYS_stat].sy_call = (sy_call_t *) filemon_wrapper_stat; sv_table[SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink; @@ -687,6 +756,7 @@ filemon_wrapper_install(void) sv_table[FREEBSD32_SYS_freebsd32_execve].sy_call = (sy_call_t *) filemon_wrapper_freebsd32_execve; sv_table[FREEBSD32_SYS_fork].sy_call = (sy_call_t *) filemon_wrapper_fork; sv_table[FREEBSD32_SYS_open].sy_call = (sy_call_t *) filemon_wrapper_open; + sv_table[FREEBSD32_SYS_openat].sy_call = (sy_call_t *) filemon_wrapper_openat; sv_table[FREEBSD32_SYS_rename].sy_call = (sy_call_t *) filemon_wrapper_rename; sv_table[FREEBSD32_SYS_freebsd32_stat].sy_call = (sy_call_t *) filemon_wrapper_freebsd32_stat; sv_table[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink; @@ -713,6 +783,7 @@ filemon_wrapper_deinstall(void) sv_table[SYS_execve].sy_call = (sy_call_t *)sys_execve; sv_table[SYS_fork].sy_call = (sy_call_t *)sys_fork; sv_table[SYS_open].sy_call = (sy_call_t *)sys_open; + sv_table[SYS_openat].sy_call = (sy_call_t *)sys_openat; sv_table[SYS_rename].sy_call = (sy_call_t *)sys_rename; sv_table[SYS_stat].sy_call = (sy_call_t *)sys_stat; sv_table[SYS_unlink].sy_call = (sy_call_t *)sys_unlink; @@ -731,6 +802,7 @@ filemon_wrapper_deinstall(void) sv_table[FREEBSD32_SYS_freebsd32_execve].sy_call = (sy_call_t *)freebsd32_execve; sv_table[FREEBSD32_SYS_fork].sy_call = (sy_call_t *)sys_fork; sv_table[FREEBSD32_SYS_open].sy_call = (sy_call_t *)sys_open; + sv_table[FREEBSD32_SYS_openat].sy_call = (sy_call_t *)sys_openat; sv_table[FREEBSD32_SYS_rename].sy_call = (sy_call_t *)sys_rename; sv_table[FREEBSD32_SYS_freebsd32_stat].sy_call = (sy_call_t *)freebsd32_stat; sv_table[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *)sys_unlink;