init not showing the printk that I want it to

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 .


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.


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.

链接地址: http://www.djcxy.com/p/78118.html

上一篇: 如何排除要删除的文件/文件夹

下一篇: init没有显示我想要的printk