[RFC][PATCH] Inotify kernel API
Amy Griffis
amy.griffis at hp.com
Sat Aug 27 00:31:33 UTC 2005
I'm attaching a small demonstration module that uses the Inotify
kernel API from my patch, in case anyone is interested.
It takes a watch path (file or directory) as a parameter on init:
# insmod imod.ko watch_path=/tmp/foo
This is just a simple client, so the file/directory must exist. :-)
Regards,
Amy
-------------- next part --------------
#include <linux/module.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
#include <linux/inotify.h>
#include <linux/namei.h>
static char *watch_path = "";
module_param(watch_path, charp, 0);
static struct inotify_device *dev;
static s32 wd;
static char *mylist[] = { "bike", "hack", "eat", "sleep", "rinse", "repeat" };
static void handle_inotify_event(struct inotify_event *event, const char *path,
void *arg)
{
char *myactivity = arg;
printk(KERN_DEBUG
"imod: wd=%08x, mask=%08x, cookie=%x, path=\"%s\", arg=\"%s\"\n",
event->wd, event->mask, event->cookie, path ?: "(null)",
myactivity);
}
static int __init imod_init(void)
{
struct nameidata nd;
int retval;
if (*watch_path == '\0') {
printk(KERN_DEBUG "imod: watch_path must be specified\n");
return -EINVAL;
}
retval = path_lookup(watch_path, 0, &nd);
if (retval) {
printk(KERN_DEBUG "imod: path_lookup returned %d\n", retval);
return retval;
}
dev = inotify_init(handle_inotify_event);
if (!dev) {
printk(KERN_DEBUG "imod: inotify_init failed\n");
return -ENOMEM;
}
wd = inotify_add_watch(dev, nd.dentry->d_inode, IN_ALL_EVENTS,
mylist[1]);
if (wd < 0) {
printk(KERN_DEBUG "imod: inotify_add_watch returned %d\n", wd);
return wd;
}
return 0;
}
static void __exit imod_cleanup(void)
{
inotify_free(dev);
}
module_init(imod_init);
module_exit(imod_cleanup);
MODULE_LICENSE("GPL");
/* vim:set noet sw=8: */
More information about the Linux-audit
mailing list