Module parameters.
[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 static char *subject = SUBJECT;
18
19 /* Define subject as a char pointer parameter. */
20 module_param(subject, charp, 0664);
21 /* Parameter description. */
22 MODULE_PARM_DESC(subject, "Subject to say hello to.");
23
24 /* Our init function: returns 0 if successfull, an error code, otherwise. */
25 static int __init hello_init(void)
26 {
27         /* printk is just like printf, but without floating point support. */
28         printk(KERN_ALERT "Hello, %s!\n", subject);
29         return 0;
30 }
31
32 /* Our exit function: static is good, so we do not pollute namespace. */
33 static void __exit hello_exit(void)
34 {
35         /* KERN_ALERT is a string macro prepended to our message. */
36         printk(KERN_ALERT "Goodbye, cruel %s!\n", subject);
37 }
38
39 /* Here, we declare our module init and exit functions. */
40 module_init(hello_init);
41 module_exit(hello_exit);