kernel inotify api问题

hycf_123 2017-07-05 04:48:03
Kernel版本2.6.32

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/namei.h>
#include <linux/path.h>
#include <linux/inotify.h>
MODULE_LICENSE("GPL");

struct inotify_handle *ih;

void m_handle_event(struct inotify_watch *watch,u32 wd,u32 mask,u32 cookie,const char *name,struct inode *inode) {
printk("monitor handle event\n");
}

void m_destroy_watch(struct inotify_watch *watch) {
inotify_rm_watch(ih,watch);
printk("monitor destroy watch\n");
}

int init_module() {
struct inotify_watch iw;
struct inode *id;
struct path path;
struct inotify_operations ops;
char *p = "/root/test";
int err;
ops.handle_event = m_handle_event;
ops.destroy_watch = m_destroy_watch;
ih = inotify_init(&ops);
err = kern_path(p, LOOKUP_FOLLOW, &path);
if (err)
return err;
id = path.dentry->d_inode;
inotify_init_watch(&iw);
inotify_add_watch(ih,&iw,id,IN_OPEN);
return 0;
}

void cleanup_module() {
inotify_destroy(ih);
printk(KERN_ALERT"Remove Module!\n");
}

make没问题,insmod之后打开“/root/test”文件就crash了。。。

求大佬给看看。。。
...全文
408 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧