Calling kernel module initialization and shutdown functions in the wrong order

I make a very simple world hello world module and get some crazy behavior. This worked until I upgraded to kernel 3.3.8, and now ... Well, it calls the init function on exit and the exit function on initialization. I made sure my names are correct.

 // Needed for module definitions #include <linux/module.h> // Needed for initilization modules #include <linux/init.h> // Must declare some license MODULE_LICENSE("Dual BSD/GPL"); // Function to be called on insmod // Returns 0 on success static int __init mymod_init(void) { // Prints kernel alert. Check /var/log/syslog printk(KERN_ALERT "Module was loaded, this is the printk."); return 0; } // Function to be called on rmmod static void __exit mymod_exit(void) { // Prints kernel alert. Check /var/log/syslog printk(KERN_ALERT "Module was unloaded, this is the printk"); } // Register these functions module_init(mymod_init); module_exit(mymod_exit); 

Output Example:

root @ cop4610: /home/cop4610/Downloads/linux-3.3.8/mymodule# insmod mymodule.ko root @ cop4610: /home/cop4610/Downloads/linux-3.3.8/mymodule# tail / var / log / syslog Oct 12 10:08:20 Kernel cop4610: [633.567832] The module has been unloaded, this is printk

The following is a live video of what is happening: http://www.youtube.com/watch?v=8aJNSpCd7as&feature=youtu.be

+8
c linux module kernel kernel-module
source share
2 answers

He needed a new line !!!!!! Arrggg !!!

  printk(KERN_ALERT "Module was unloaded, this is the printk\n"); 

and

  printk(KERN_ALERT "Module was loaded, this is the printk\n"); 

It seems that in fact they did not fail, it just seemed because the first one did not appear until the second one was released, since the buffer was not flushed.

+13
source share

This is my main example:

 #include <linux/module.h> #include <linux/kernel.h> #define MODULE_NAME "hello_md" MODULE_LICENSE("GPL"); MODULE_AUTHOR("B3h3m0th"); MODULE_DESCRIPTION("Basic LKM; hello world module"); MODULE_VERSION("0.0"); static int __init insert_mod(void) { printk(KERN_ALERT "[%s] Init: \"Hello World\"\n", MODULE_NAME); return 0; } static void __exit remove_mod(void) { printk(KERN_ALERT "[%s] Exit\n", MODULE_NAME); } module_init(insert_mod); module_exit(remove_mod); 

My main Makefile:

 obj-m += basic_module.o KERNELVERSION = $(shell uname -r) all: $(MAKE) -C /lib/modules/$(KERNELVERSION)/build M=$(PWD) modules clean: $(MAKE) -C /lib/modules/$(KERNELVERSION)/build M=$(PWD) clean 
+1
source share

All Articles