免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5082 | 回复: 9
打印 上一主题 下一主题

求助,module_init函数不执行 [复制链接]

招聘 : c/c++研发
论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-14 14:20 |只看该作者 |倒序浏览

  1. #include <linux/module.h>   // Needed by all modules
  2. #include <linux/kernel.h>   // Needed for KERN_ALERT
  3. #include <linux/init.h>     // Needed for the macros
  4. MODULE_LICENSE("GPL");

  5. static int hello_2_init(void)
  6. {
  7.    printk(KERN_ALERT"Hello, world 2\n");
  8.    return 0;
  9. }


  10. static void hello_2_exit(void)
  11. {
  12.    printk(KERN_ALERT"Goodbye, world 2\n");
  13. }


  14. module_init(hello_2_init);
  15. module_exit(hello_2_exit);
复制代码


代码如上,insmod的时候毫无反应,rmmod能正常printk,有人遇见过这样的问题吗?
系统是rhas5,新装的,以前装的系统都没出现这问题。

[ 本帖最后由 jerryhua 于 2008-3-14 14:23 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-03-14 14:27 |只看该作者
你是在虚拟控制台ismod的吧。退出x-window界面,在console做应该就可以显示了。

招聘 : c/c++研发
论坛徽章:
0
3 [报告]
发表于 2008-03-14 14:33 |只看该作者
原帖由 richardhesidu 于 2008-3-14 14:27 发表
你是在虚拟控制台ismod的吧。退出x-window界面,在console做应该就可以显示了。

没用xwindow,我直接tail -f /var/log/message,模块退出时的退出清理函数正常执行,但模块初始化函数似乎没有注册上。很怪异

论坛徽章:
0
4 [报告]
发表于 2008-03-14 14:49 |只看该作者

回复 #3 jerryhua 的帖子

不要用tail -f, 用dmesg吧,还没有?

招聘 : c/c++研发
论坛徽章:
0
5 [报告]
发表于 2008-03-14 14:56 |只看该作者
原帖由 albcamus 于 2008-3-14 14:49 发表
不要用tail -f, 用dmesg吧,还没有?


  1. #include <linux/module.h>   // Needed by all modules
  2. #include <linux/kernel.h>   // Needed for KERN_ALERT
  3. #include <linux/init.h>     // Needed for the macros
  4. MODULE_LICENSE("GPL");
  5. static int i=0;

  6. static int __init hello_2_init(void)
  7. {
  8.         i=1;
  9.    printk(KERN_EMERG"Hello, world 2\n");
  10.    return 0;
  11. }


  12. static void hello_2_exit(void)
  13. {
  14.    printk(KERN_ALERT"Goodbye, world 2,i=%d\n",i);
  15. }

  16. module_init(hello_2_init);
  17. module_exit(hello_2_exit);
  18.       
复制代码


用dmesg结果一样,我改了下代码增加一个监控变量,结果日志中记录如下
Goodbye, world 2,i=0
显然hello_2_init()根本没被调用

论坛徽章:
0
6 [报告]
发表于 2008-03-14 15:33 |只看该作者
原帖由 jerryhua 于 2008-3-14 14:56 发表



#include    // Needed by all modules
#include    // Needed for KERN_ALERT
#include      // Needed for the macros
MODULE_LICENSE("GPL");
static int i=0;

static int __init hello_2_init ...



不会吧? 如果init函数不被成功执行的话, inmod根本不可能成功, 模块无法加载的。

招聘 : c/c++研发
论坛徽章:
0
7 [报告]
发表于 2008-03-14 15:46 |只看该作者
原帖由 albcamus 于 2008-3-14 15:33 发表



不会吧? 如果init函数不被成功执行的话, inmod根本不可能成功, 模块无法加载的。

这也是我疑惑的地方啊,lsmod看到模块确实加载了,但变量的值显示init函数没执行,我换init_module()试了一下也一样。

论坛徽章:
0
8 [报告]
发表于 2008-03-14 16:18 |只看该作者

回复 #7 jerryhua 的帖子

你在hello_2_init调用一句 panic("test1234")试试?  :mrgreen:

论坛徽章:
0
9 [报告]
发表于 2008-03-14 16:22 |只看该作者
原帖由 jerryhua 于 2008-3-14 15:46 发表

这也是我疑惑的地方啊,lsmod看到模块确实加载了,但变量的值显示init函数没执行,我换init_module()试了一下也一样。

lsmod看错了吧,兄弟

招聘 : c/c++研发
论坛徽章:
0
10 [报告]
发表于 2008-03-17 09:14 |只看该作者

回复 #8 albcamus 的帖子

还是一样没任何反应
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP