Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/filemon staircase flattening police.
details: https://anonhg.NetBSD.org/src/rev/0ca8b73aae5b
branches: trunk
changeset: 338900:0ca8b73aae5b
user: christos <christos%NetBSD.org@localhost>
date: Mon Jun 15 19:45:31 2015 +0000
description:
staircase flattening police.
diffstat:
sys/dev/filemon/filemon_wrapper.c | 364 +++++++++++++++++++------------------
1 files changed, 185 insertions(+), 179 deletions(-)
diffs (truncated from 499 to 300 lines):
diff -r 4d4fd7e957c8 -r 0ca8b73aae5b sys/dev/filemon/filemon_wrapper.c
--- a/sys/dev/filemon/filemon_wrapper.c Mon Jun 15 18:11:36 2015 +0000
+++ b/sys/dev/filemon/filemon_wrapper.c Mon Jun 15 19:45:31 2015 +0000
@@ -1,3 +1,5 @@
+/* $NetBSD: filemon_wrapper.c,v 1.7 2015/06/15 19:45:31 christos Exp $ */
+
/*
* Copyright (c) 2010, Juniper Networks, Inc.
*
@@ -24,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: filemon_wrapper.c,v 1.6 2015/06/15 18:11:36 sjg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: filemon_wrapper.c,v 1.7 2015/06/15 19:45:31 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -41,27 +43,27 @@
filemon_wrapper_chdir(struct lwp * l, const struct sys_chdir_args * uap,
register_t * retval)
{
- int ret;
int error;
size_t done;
struct filemon *filemon;
- if ((ret = sys_chdir(l, uap, retval)) == 0) {
- filemon = filemon_lookup(curproc);
+ if ((error = sys_chdir(l, uap, retval)) != 0)
+ return 0;
- if (filemon) {
+ filemon = filemon_lookup(curproc);
+ if (filemon == NULL)
+ return 0;
- error = copyinstr(SCARG(uap, path), filemon->fm_fname1,
- sizeof(filemon->fm_fname1), &done);
- if (error == 0) {
- filemon_printf(filemon,
- "C %d %s\n",
- curproc->p_pid, filemon->fm_fname1);
- }
- rw_exit(&filemon->fm_mtx);
- }
- }
- return (ret);
+ error = copyinstr(SCARG(uap, path), filemon->fm_fname1,
+ sizeof(filemon->fm_fname1), &done);
+ if (error)
+ goto out;
+
+ filemon_printf(filemon, "C %d %s\n",
+ curproc->p_pid, filemon->fm_fname1);
+out:
+ rw_exit(&filemon->fm_mtx);
+ return 0;
}
static int
@@ -69,232 +71,234 @@
register_t * retval)
{
char fname[MAXPATHLEN];
- int ret;
int error;
size_t done;
struct filemon *filemon;
- error = copyinstr(SCARG(uap, path), fname, sizeof(fname), &done);
+ if ((error = sys_execve(l, uap, retval)) != EJUSTRETURN)
+ return 0;
- if ((ret = sys_execve(l, uap, retval)) == EJUSTRETURN && error == 0) {
- filemon = filemon_lookup(curproc);
+ filemon = filemon_lookup(curproc);
+ if (filemon == NULL)
+ return 0;
- if (filemon) {
- filemon_printf(filemon, "E %d %s\n",
- curproc->p_pid, fname);
- rw_exit(&filemon->fm_mtx);
- }
- }
- return (ret);
+ error = copyinstr(SCARG(uap, path), fname, sizeof(fname), &done);
+ if (error)
+ goto out;
+
+ filemon_printf(filemon, "E %d %s\n", curproc->p_pid, fname);
+out:
+ rw_exit(&filemon->fm_mtx);
+ return 0;
}
static int
filemon_wrapper_fork(struct lwp * l, const void *v, register_t * retval)
{
- int ret;
+ int error;
struct filemon *filemon;
- if ((ret = sys_fork(l, v, retval)) == 0) {
- filemon = filemon_lookup(curproc);
+ if ((error = sys_fork(l, v, retval)) != 0)
+ return error;
- if (filemon) {
- filemon_printf(filemon, "F %d %ld\n",
- curproc->p_pid, (long) retval[0]);
- rw_exit(&filemon->fm_mtx);
- }
- }
- return (ret);
+ filemon = filemon_lookup(curproc);
+ if (filemon == NULL)
+ return 0;
+
+ filemon_printf(filemon, "F %d %ld\n", curproc->p_pid, (long) retval[0]);
+
+ rw_exit(&filemon->fm_mtx);
+ return 0;
}
static int
filemon_wrapper_vfork(struct lwp * l, const void *v, register_t * retval)
{
- int ret;
+ int error;
struct filemon *filemon;
- if ((ret = sys_vfork(l, v, retval)) == 0) {
- filemon = filemon_lookup(curproc);
+ if ((error = sys_vfork(l, v, retval)) != 0)
+ return error;
+
+ filemon = filemon_lookup(curproc);
+ if (filemon == NULL)
+ return 0;
+
+ filemon_printf(filemon, "F %d %ld\n", curproc->p_pid, (long) retval[0]);
- if (filemon) {
- filemon_printf(filemon, "F %d %ld\n",
- curproc->p_pid, (long) retval[0]);
- rw_exit(&filemon->fm_mtx);
- }
+ rw_exit(&filemon->fm_mtx);
+ return 0;
+}
+
+static void
+filemon_flags(struct filemon * filemon, int f)
+{
+ if (f & O_RDWR) {
+ /* we want a separate R record */
+ filemon_printf(filemon, "R %d %s\n", curproc->p_pid,
+ filemon->fm_fname1);
}
- return (ret);
+
+ filemon_printf(filemon, "%c %d %s\n", (f & O_ACCMODE) ? 'W' : 'R',
+ curproc->p_pid, filemon->fm_fname1);
}
static int
filemon_wrapper_open(struct lwp * l, struct sys_open_args * uap,
register_t * retval)
{
- int ret;
int error;
size_t done;
struct filemon *filemon;
- if ((ret = sys_open(l, uap, retval)) == 0) {
- filemon = filemon_lookup(curproc);
+ if ((error = sys_open(l, uap, retval)) != 0)
+ return error;
+
+ filemon = filemon_lookup(curproc);
+ if (filemon == NULL)
+ return 0;
- if (filemon) {
- error = copyinstr(SCARG(uap, path), filemon->fm_fname1,
- sizeof(filemon->fm_fname1), &done);
- if (error == 0) {
- if (SCARG(uap, flags) & 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, flags) & O_ACCMODE) ? 'W' : 'R',
- curproc->p_pid, filemon->fm_fname1);
- }
- rw_exit(&filemon->fm_mtx);
- }
- }
- return (ret);
+ error = copyinstr(SCARG(uap, path), filemon->fm_fname1,
+ sizeof(filemon->fm_fname1), &done);
+ if (error)
+ goto out;
+
+ filemon_flags(filemon, SCARG(uap, flags));
+out:
+ rw_exit(&filemon->fm_mtx);
+ return 0;
}
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 ((error = sys_openat(l, uap, retval)) != 0)
+ return error;
+
+ filemon = filemon_lookup(curproc);
+ if (filemon == NULL)
+ return 0;
+
+ error = copyinstr(SCARG(uap, path), filemon->fm_fname1,
+ sizeof(filemon->fm_fname1), &done);
+ if (error)
+ goto out;
- 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);
- }
+ 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);
}
- return (ret);
+
+ filemon_flags(filemon, SCARG(uap, oflags));
+out:
+ rw_exit(&filemon->fm_mtx);
+ return 0;
}
static int
filemon_wrapper_rename(struct lwp * l, struct sys_rename_args * uap,
register_t * retval)
{
- int ret;
int error;
size_t done;
struct filemon *filemon;
- if ((ret = sys_rename(l, uap, retval)) == 0) {
- filemon = filemon_lookup(curproc);
+ if ((error = sys_rename(l, uap, retval)) != 0)
+ return error;
+
+ filemon = filemon_lookup(curproc);
Home |
Main Index |
Thread Index |
Old Index