notifier实例

#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();
}



































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

九月天-深圳专业软硬件开发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值