notifier实例

来源:互联网 发布:神华招标采购 知乎 编辑:程序博客网 时间:2024/05/01 01:06
#include<linux/notifier.h>
#include<linux/module.h>
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/fs.h>


#define TESTCHAIN_INIT 0x52U


static RAW_NOTIFIER_HEAD(test_chain);


static int call_test_notifier(unsigned long val,void *v)
{
return raw_notifier_call_chain(&test_chain,val,v);
}
EXPORT_SYMBOL(call_test_notifier);


static int register_test_notifier(struct notifier_block *nb)
{
int err;
err = raw_notifier_chain_register(&test_chain,nb);
if(err)
goto out;
out:
return err;
}
EXPORT_SYMBOL(register_test_notifier);


static int __init test_chain_0_init(void)
{
printk("**%s**\n",__FUNCTION__);
return 0;
}


static void __exit test_chain_0_exit(void)
{
printk("***%s***\n",__FUNCTION__);
}


module_init(test_chain_0_init);
module_exit(test_chain_0_exit);




#include<linux/notifier.h>
#include<linux/module.h>
#include<linux/init.h>


#include<linux/kernel.h>
#include<linux/fs.h>


extern int register_test_notifier(struct notifier_block *nb);
#define TESTCHAIN_INIT 0x52U


int test_init_event(struct notifier_block *nb,unsigned long event,void *v)
{
switch(event)
{
case TESTCHAIN_INIT:
printk("**testchain_init**");
break;
default:
break;
}
return NOTIFY_DONE;
}


static struct notifier_block test_init_notifier = 
{
.notifier_call = test_init_event,
};


static int __init test_chain_1_init(void)
{
printk("**i am in test_chain_1\n");
register_test_notifier(&test_init_notifier);
return 0;
}
static void __exit test_chain_1_exit(void)
{
printk();
}
module_init();
module_exit();




#include...




extern int call_test_notifier(unsigned long val,void *v)
#define TESTCHAIN_INIT 0X52U


static int __init test_chain_2_init(void)
{
printk("***i am in test_chain_2\n");
call_test_notifier(TESTCHAIN_INIT,"no_use");

return 0;
}
static void __exit test_chain_2_exit(void)
{
printk();
}



































0 0
原创粉丝点击