Module_init does not show printk what I want it to

I am trying to make my module printk displayable. I am new to this, so I may have some programming errors. This is the file of my C module:

 #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 of all, I don’t know how exactly the arrow pointer works, so I usually omit it from printk , so it compiles fine. 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 into the terminal and then output the message using dmesg , I get a module_init message that calls sys_mycall , but I can not add any arguments to it and it displays a message but it shows nothing for firstname or for myid .

0
c linux module terminal kernel
source share
2 answers

I think the problem is that the init module does not expect any parameters in the function, it must be invalid (you can add them differently), so basically your function is called with garbage that is currently on the stack, which there may be nothing, but it is probably zero, because otherwise your kernel will work.

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

+1
source share

You do not have a log level specified, so I suspect that it is filtered as below the threshold. Attach KERN_WARNING in front of the format string and make sure it prints. A message without a log level is interpreted at CONFIG_DEFAULT_MESSAGE_LOGLEVEL from your .config file.

0
source share

All Articles