Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/filemon Latest clang uses openat, filemon thus needs...



details:   https://anonhg.NetBSD.org/src/rev/4d4fd7e957c8
branches:  trunk
changeset: 338899:4d4fd7e957c8
user:      sjg <sjg%NetBSD.org@localhost>
date:      Mon Jun 15 18:11:36 2015 +0000

description:
Latest clang uses openat, filemon thus needs to handle it.

For the simple cases where path is absolute or dirfd is for cwd
we can handle this just like open.
For the remaining case we output an 'A' record to offer a clue that
a search for open dir is needed (earlier in the trace).

diffstat:

 sys/dev/filemon/filemon_wrapper.c |  49 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 48 insertions(+), 1 deletions(-)

diffs (80 lines):

diff -r 2c87307a9c86 -r 4d4fd7e957c8 sys/dev/filemon/filemon_wrapper.c
--- a/sys/dev/filemon/filemon_wrapper.c Mon Jun 15 16:53:17 2015 +0000
+++ b/sys/dev/filemon/filemon_wrapper.c Mon Jun 15 18:11:36 2015 +0000
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: filemon_wrapper.c,v 1.5 2014/03/27 18:27:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: filemon_wrapper.c,v 1.6 2015/06/15 18:11:36 sjg Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -160,6 +160,51 @@
 }
 
 static int
+filemon_wrapper_openat(struct lwp * l, struct sys_openat_args * uap,
+    register_t * retval)
+{
+       int ret;
+       int error;
+       size_t done;
+       struct filemon *filemon;
+
+       if ((ret = sys_openat(l, uap, retval)) == 0) {
+               filemon = filemon_lookup(curproc);
+
+               if (filemon) {
+                       error = copyinstr(SCARG(uap, path), filemon->fm_fname1,
+                           sizeof(filemon->fm_fname1), &done);
+                       if (error == 0) {
+                               if (filemon->fm_fname1[0] != '/' &&
+                                   SCARG(uap, fd) != AT_FDCWD) {
+                                       /*
+                                        * Rats we cannot just treat like open.
+                                        * Output an 'A' record as a clue.
+                                        */
+                                       filemon_printf(filemon,
+                                               "A %d %s\n",
+                                               curproc->p_pid,
+                                               filemon->fm_fname1);
+                               }
+                               if (SCARG(uap, oflags) & O_RDWR) {
+                                       /* we want a separate R record */
+                                       filemon_printf(filemon,
+                                               "R %d %s\n",
+                                               curproc->p_pid,
+                                               filemon->fm_fname1);
+                               }                       
+                               filemon_printf(filemon,
+                                   "%c %d %s\n",
+                                   (SCARG(uap, oflags) & O_ACCMODE) ? 'W' : 'R',
+                                   curproc->p_pid, filemon->fm_fname1);
+                       }
+                       rw_exit(&filemon->fm_mtx);
+               }
+       }
+       return (ret);
+}
+
+static int
 filemon_wrapper_rename(struct lwp * l, struct sys_rename_args * uap,
     register_t * retval)
 {
@@ -311,6 +356,7 @@
        sv_table[SYS_fork].sy_call = (sy_call_t *) filemon_wrapper_fork;
        sv_table[SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link;
        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_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink;
        sv_table[SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink;
@@ -330,6 +376,7 @@
        sv_table[SYS_fork].sy_call = (sy_call_t *) sys_fork;
        sv_table[SYS_link].sy_call = (sy_call_t *) sys_link;
        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_symlink].sy_call = (sy_call_t *) sys_symlink;
        sv_table[SYS_unlink].sy_call = (sy_call_t *) sys_unlink;



Home | Main Index | Thread Index | Old Index