module_init not showing the printk that I want it to

拟墨画扇 提交于 2019-12-11 14:18:54

问题


I am trying to make my module display a printk. I'm new to this so I might have some programming errors. This is my module C file:

#include <linux/linkage.h>
#include <linux/time.h>
#include <linux/module.h>

asmlinkage long sys_mycall(int myid, char* firstname)
{
    printk ("Hello, %s! \n sys_mycall called from process %d with  ID %d. \n",
        firstname, current->id, myid);

    return 0;
}

static int my_init(void)
{
    return 0;
}

static int my_exit(void)
{
    printk("Goodbye!");
    return 0;
}

module_init(sys_mycall);
module_exit(my_exit);

First thing is that I don't know how the arrow pointer exactly works so I usually omit it from the printk so it compiles perfectly. If someone can give me a link or something on how to understand it I would really appreciate it.

When I insert it using insmod in the terminal and then display the message using dmesg I get the message by the module_init calling the sys_mycall but I cannot add any arguments to it and it displays the message but it doesn't show anything for firstname or for myid.


回答1:


I think the problem that module init expect no parameters in the function, it must be void (you can add them in a different way), so basically your function is called with garbage that is currently in the stack, which might be anything but it probably zero as otherwise your kernel will crash.

what do you want to print? I understand current->id, but no the others.




回答2:


You have no log level specified, so I suspect it's being filtered out as below the threshold. Stick a KERN_WARNING in front of your format string and verify that it prints. Message without a log level are interpreted at CONFIG_DEFAULT_MESSAGE_LOGLEVEL from your .config file.



来源:https://stackoverflow.com/questions/10837446/module-init-not-showing-the-printk-that-i-want-it-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!