summaryrefslogtreecommitdiffstats
path: root/sys/dev/filemon
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2016-03-14 07:56:21 -0300
committerRenato Botelho <renato@netgate.com>2016-03-14 07:56:21 -0300
commita26e4b3de35515ec3eaf2eb76b001a6a502bf56c (patch)
tree66dd86f3e16db9b45f07c989e95501b6456cf6a5 /sys/dev/filemon
parent7d66bf7f17e48798ec04b7a6d99daff1820e28f8 (diff)
parenta64e8d254dc9ecd38594b71dcd7d53c6084c5abc (diff)
downloadFreeBSD-src-a26e4b3de35515ec3eaf2eb76b001a6a502bf56c.zip
FreeBSD-src-a26e4b3de35515ec3eaf2eb76b001a6a502bf56c.tar.gz
Merge remote-tracking branch 'origin/stable/10' into devel
Diffstat (limited to 'sys/dev/filemon')
-rw-r--r--sys/dev/filemon/filemon.c33
-rw-r--r--sys/dev/filemon/filemon_lock.c14
-rw-r--r--sys/dev/filemon/filemon_wrapper.c75
3 files changed, 33 insertions, 89 deletions
diff --git a/sys/dev/filemon/filemon.c b/sys/dev/filemon/filemon.c
index 352f682..cd40c5a 100644
--- a/sys/dev/filemon/filemon.c
+++ b/sys/dev/filemon/filemon.c
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <sys/file.h>
#include <sys/systm.h>
#include <sys/buf.h>
+#include <sys/capsicum.h>
#include <sys/condvar.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
@@ -52,10 +53,6 @@ __FBSDID("$FreeBSD$");
#include <sys/sysproto.h>
#include <sys/uio.h>
-#if __FreeBSD_version >= 900041
-#include <sys/capsicum.h>
-#endif
-
#include "filemon.h"
#if defined(COMPAT_IA32) || defined(COMPAT_FREEBSD32) || defined(COMPAT_ARCH32)
@@ -71,8 +68,6 @@ extern struct sysentvec elf64_freebsd_sysvec;
static d_close_t filemon_close;
static d_ioctl_t filemon_ioctl;
static d_open_t filemon_open;
-static int filemon_unload(void);
-static void filemon_load(void *);
static struct cdevsw filemon_cdevsw = {
.d_version = D_VERSION,
@@ -130,7 +125,7 @@ filemon_dtr(void *data)
/* Follow same locking order as filemon_pid_check. */
filemon_lock_write();
- filemon_filemon_lock(filemon);
+ sx_xlock(&filemon->lock);
/* Remove from the in-use list. */
TAILQ_REMOVE(&filemons_inuse, filemon, link);
@@ -143,7 +138,7 @@ filemon_dtr(void *data)
TAILQ_INSERT_TAIL(&filemons_free, filemon, link);
/* Give up write access. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
filemon_unlock_write();
if (fp != NULL)
@@ -158,25 +153,23 @@ filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused,
int error = 0;
struct filemon *filemon;
struct proc *p;
-#if __FreeBSD_version >= 900041
cap_rights_t rights;
-#endif
if ((error = devfs_get_cdevpriv((void **) &filemon)) != 0)
return (error);
- filemon_filemon_lock(filemon);
+ sx_xlock(&filemon->lock);
switch (cmd) {
/* Set the output file descriptor. */
case FILEMON_SET_FD:
- if (filemon->fp != NULL)
- fdrop(filemon->fp, td);
+ if (filemon->fp != NULL) {
+ error = EEXIST;
+ break;
+ }
error = fget_write(td, *(int *)data,
-#if __FreeBSD_version >= 900041
cap_rights_init(&rights, CAP_PWRITE),
-#endif
&filemon->fp);
if (error == 0)
/* Write the file header. */
@@ -198,7 +191,7 @@ filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused,
break;
}
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
return (error);
}
@@ -308,6 +301,14 @@ filemon_modevent(module_t mod __unused, int type, void *data)
error = filemon_unload();
break;
+ case MOD_QUIESCE:
+ /*
+ * The wrapper implementation is unsafe for reliable unload.
+ * Require forcing an unload.
+ */
+ error = EBUSY;
+ break;
+
case MOD_SHUTDOWN:
break;
diff --git a/sys/dev/filemon/filemon_lock.c b/sys/dev/filemon/filemon_lock.c
index a0347000..5cac47c 100644
--- a/sys/dev/filemon/filemon_lock.c
+++ b/sys/dev/filemon/filemon_lock.c
@@ -29,20 +29,6 @@
__FBSDID("$FreeBSD$");
static __inline void
-filemon_filemon_lock(struct filemon *filemon)
-{
-
- sx_xlock(&filemon->lock);
-}
-
-static __inline void
-filemon_filemon_unlock(struct filemon *filemon)
-{
-
- sx_xunlock(&filemon->lock);
-}
-
-static __inline void
filemon_lock_read(void)
{
diff --git a/sys/dev/filemon/filemon_wrapper.c b/sys/dev/filemon/filemon_wrapper.c
index 40e09e3..ccadbce 100644
--- a/sys/dev/filemon/filemon_wrapper.c
+++ b/sys/dev/filemon/filemon_wrapper.c
@@ -36,27 +36,6 @@ __FBSDID("$FreeBSD$");
#include "opt_compat.h"
-#if __FreeBSD_version > 800032
-#define FILEMON_HAS_LINKAT
-#endif
-
-#if __FreeBSD_version < 900044 /* r225617 (2011-09-16) failed to bump
- __FreeBSD_version. This really should
- be based on "900045". "900044" is r225469
- (2011-09-10) so this code is broken for
- 9-CURRENT September 10th-16th. */
-#define sys_chdir chdir
-#define sys_link link
-#define sys_open open
-#define sys_rename rename
-#define sys_stat stat
-#define sys_symlink symlink
-#define sys_unlink unlink
-#ifdef FILEMON_HAS_LINKAT
-#define sys_linkat linkat
-#endif
-#endif /* __FreeBSD_version */
-
static eventhandler_tag filemon_exec_tag;
static eventhandler_tag filemon_exit_tag;
static eventhandler_tag filemon_fork_tag;
@@ -80,7 +59,8 @@ filemon_output(struct filemon *filemon, char *msg, size_t len)
auio.uio_td = curthread;
auio.uio_offset = (off_t) -1;
- bwillwrite();
+ if (filemon->fp->f_type == DTYPE_VNODE)
+ bwillwrite();
fo_write(filemon->fp, &auio, curthread->td_ucred, 0, curthread);
}
@@ -100,7 +80,7 @@ filemon_pid_check(struct proc *p)
TAILQ_FOREACH(filemon, &filemons_inuse, link) {
if (p == filemon->p) {
sx_sunlock(&proctree_lock);
- filemon_filemon_lock(filemon);
+ sx_xlock(&filemon->lock);
filemon_unlock_read();
return (filemon);
}
@@ -131,8 +111,7 @@ filemon_wrapper_chdir(struct thread *td, struct chdir_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -160,8 +139,7 @@ filemon_event_process_exec(void *arg __unused, struct proc *p,
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
free(freepath, M_TEMP);
}
@@ -199,8 +177,7 @@ filemon_wrapper_open(struct thread *td, struct open_args *uap)
curproc->p_pid, filemon->fname1);
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -252,8 +229,7 @@ filemon_wrapper_openat(struct thread *td, struct openat_args *uap)
curproc->p_pid, filemon->fname2, filemon->fname1);
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -281,8 +257,7 @@ filemon_wrapper_rename(struct thread *td, struct rename_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -310,8 +285,7 @@ filemon_wrapper_link(struct thread *td, struct link_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -339,15 +313,13 @@ filemon_wrapper_symlink(struct thread *td, struct symlink_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
return (ret);
}
-#ifdef FILEMON_HAS_LINKAT
static int
filemon_wrapper_linkat(struct thread *td, struct linkat_args *uap)
{
@@ -369,14 +341,12 @@ filemon_wrapper_linkat(struct thread *td, struct linkat_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
return (ret);
}
-#endif
static int
filemon_wrapper_stat(struct thread *td, struct stat_args *uap)
@@ -397,8 +367,7 @@ filemon_wrapper_stat(struct thread *td, struct stat_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -426,8 +395,7 @@ filemon_wrapper_freebsd32_stat(struct thread *td,
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -462,8 +430,7 @@ filemon_event_process_exit(void *arg __unused, struct proc *p)
filemon->p = NULL;
}
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -486,8 +453,7 @@ filemon_wrapper_unlink(struct thread *td, struct unlink_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -508,8 +474,7 @@ filemon_event_process_fork(void *arg __unused, struct proc *p1,
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -530,9 +495,7 @@ filemon_wrapper_install(void)
sv_table[SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink;
sv_table[SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link;
sv_table[SYS_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink;
-#ifdef FILEMON_HAS_LINKAT
sv_table[SYS_linkat].sy_call = (sy_call_t *) filemon_wrapper_linkat;
-#endif
#if defined(COMPAT_IA32) || defined(COMPAT_FREEBSD32) || defined(COMPAT_ARCH32)
sv_table = ia32_freebsd_sysvec.sv_table;
@@ -545,9 +508,7 @@ filemon_wrapper_install(void)
sv_table[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink;
sv_table[FREEBSD32_SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link;
sv_table[FREEBSD32_SYS_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink;
-#ifdef FILEMON_HAS_LINKAT
sv_table[FREEBSD32_SYS_linkat].sy_call = (sy_call_t *) filemon_wrapper_linkat;
-#endif
#endif /* COMPAT_ARCH32 */
filemon_exec_tag = EVENTHANDLER_REGISTER(process_exec,
@@ -575,9 +536,7 @@ filemon_wrapper_deinstall(void)
sv_table[SYS_unlink].sy_call = (sy_call_t *)sys_unlink;
sv_table[SYS_link].sy_call = (sy_call_t *)sys_link;
sv_table[SYS_symlink].sy_call = (sy_call_t *)sys_symlink;
-#ifdef FILEMON_HAS_LINKAT
sv_table[SYS_linkat].sy_call = (sy_call_t *)sys_linkat;
-#endif
#if defined(COMPAT_IA32) || defined(COMPAT_FREEBSD32) || defined(COMPAT_ARCH32)
sv_table = ia32_freebsd_sysvec.sv_table;
@@ -590,9 +549,7 @@ filemon_wrapper_deinstall(void)
sv_table[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *)sys_unlink;
sv_table[FREEBSD32_SYS_link].sy_call = (sy_call_t *)sys_link;
sv_table[FREEBSD32_SYS_symlink].sy_call = (sy_call_t *)sys_symlink;
-#ifdef FILEMON_HAS_LINKAT
sv_table[FREEBSD32_SYS_linkat].sy_call = (sy_call_t *)sys_linkat;
-#endif
#endif /* COMPAT_ARCH32 */
EVENTHANDLER_DEREGISTER(process_exec, filemon_exec_tag);
OpenPOWER on IntegriCloud