I'm making a very simple hello world kernel module and getting some crazy behavior. This worked until I upgraded to kernel 3.3.8 and now it... Well, it's calling the init
function on exit, and the exit
function on initialize. I've 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);
Sample output:
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 cop4610 kernel: [ 633.567832] Module was unloaded, this is the printk
The following is a video of this happening live: http://www.youtube.com/watch?v=8aJNSpCd7as&feature=youtu.be