momo zone

调核人的blog

内核通知链

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/hardirq.h>
static RAW_NOTIFIER_HEAD(test_chain);
static int test_event1(struct notifier_block *this,unsigned long event, void *ptr){
        printk(“In Event1 :Event Number is %lu, str:%s\n”,event,ptr);
        return 0;
}
static int test_event2(struct notifier_block *this,unsigned long event, void *ptr){
        printk(“In Event2 :Event Number is %lu, str:%s\n”,event,ptr);
        return 0;
}
static struct notifier_block test_notifier1={
        .notifier_call=test_event1,
};
static struct notifier_block test_notifier2={
        .notifier_call=test_event2,
};
static int __init init_chain(void){
        int err;
        pr_devel(“register init\n”);
        err=raw_notifier_chain_register(&test_chain,&test_notifier1);
        if(err){
                printk(“register test_notifier1 error\n”);
                return -EINVAL;
        }err=raw_notifier_chain_register(&test_chain,&test_notifier2);
        if(err){
                printk(“register test_notifier2 error\n”);
                return -EINVAL;
        }
        raw_notifier_call_chain(&test_chain,1,”abcdef”);
        return 0;
}
static void __exit exit_chain(void){
        raw_notifier_chain_unregister(&test_chain,&test_notifier1);
        raw_notifier_chain_unregister(&test_chain,&test_notifier2);
        pr_devel(“unregister done”);
}
module_init(init_chain);
module_exit(exit_chain);
MODULE_LICENSE(“GPL”);
Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: