我正在开发一个简单的内核模块,并且正在从命令行获取参数。我想要做的是在加载模块之前检查这些参数。
我检查了参数并返回 1 表示 init_module 函数失败,因此如果参数无效,则不会加载内核模块。
问题是模块仍然被加载,即使它没有通过参数检查(使用第一个 if 语句)。我输入sudo -f rmmod kernel_name
了,它抱怨模块很忙。如果它通过参数检查,我如何让它加载模块?
int init_module(){
//check argument here
if(failed){
//arguments are not valid. Return 1 to indicate the failure of init_module
return 1;
}
else{
register hook function here
return 0;
}
}
void cleanup_module(){
unregister hook here
}