I'm trying to make my first loadable kernel module on debian wheezy 7.5. I tried out some sample code from different tutorials on the web, but it doesn't work for me like I think it should be.
Here's my code:
#include <linux/module.h>
#include <linux/kernel.h>
void cleanup_module(void)
{
printk(KERN_INFO "exit LKM...");
}
int init_module(void)
{
printk(KERN_INFO "loading LKM...");
return 0;
}
and I'm compiling it with a Makefile looking like this
obj-m += lkm.o
all:
sudo make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
So it compiles just fine, but when I load the LKM with "$ sudo insmod lkm.ko" and then look into the log messages, it gives back "exit LKM...", so it seems like insmod calls the cleanup_module system call instead of the init_module. The same thing happens, when I use "$ sudo rmmod lkm", I get back "loading LKM.." in the log messages. So I really don't know why this is, and all I found on the web is, that insmod loads the LKM via init_module() and so on...
I'd appreciate some help or explanation for that, since I really have no clue what went wrong.
Thanks