Use init and exit marks.
[cascardo/kernel/samples/01.hello/.git] / hello.c
1 /* Must be included by every module. */
2 #include <linux/module.h>
3
4 /* Author name comes here. */
5 MODULE_AUTHOR("Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>");
6 /* Tell a user what this modules does. */
7 MODULE_DESCRIPTION("Prints a friendly message.");
8 /* Which version is this? */
9 MODULE_VERSION("1.4.0");
10 /* Should be declared to not taint the kernel. */
11 MODULE_LICENSE("GPL");
12
13 #ifndef SUBJECT
14 #define SUBJECT "world"
15 #endif
16
17 /* Our init function: returns 0 if successfull, an error code, otherwise. */
18 static int __init hello_init(void)
19 {
20         /* printk is just like printf, but without floating point support. */
21         printk(KERN_ALERT "Hello, " SUBJECT "!\n");
22         return 0;
23 }
24
25 /* Our exit function: static is good, so we do not pollute namespace. */
26 static void __exit hello_exit(void)
27 {
28         /* KERN_ALERT is a string macro prepended to our message. */
29         printk(KERN_ALERT "Goodbye, cruel " SUBJECT "!\n");
30 }
31
32 /* Here, we declare our module init and exit functions. */
33 module_init(hello_init);
34 module_exit(hello_exit);