Use a macro for the configured message subject.
[cascardo/kernel/samples/01.hello/.git] / hello.c
diff --git a/hello.c b/hello.c
index 01e8c26..772a1e3 100644 (file)
--- a/hello.c
+++ b/hello.c
@@ -1,17 +1,28 @@
+/* Must be included by every module. */
 #include <linux/module.h>
 
+/* Should be declared to not taint the kernel. */
 MODULE_LICENSE("GPL");
 
+#ifndef SUBJECT
+#define SUBJECT "world"
+#endif
+
+/* Our init function: returns 0 if successfull, an error code, otherwise. */
 static int hello_init(void)
 {
-       printk(KERN_ALERT "Hello, world!\n");
+       /* printk is just like printf, but without floating point support. */
+       printk(KERN_ALERT "Hello, " SUBJECT "!\n");
        return 0;
 }
 
+/* Our exit function: static is good, so we do not pollute namespace. */
 static void hello_exit(void)
 {
-       printk(KERN_ALERT "Goodbye, cruel world!\n");
+       /* KERN_ALERT is a string macro prepended to our message. */
+       printk(KERN_ALERT "Goodbye, cruel " SUBJECT "!\n");
 }
 
+/* Here, we declare our module init and exit functions. */
 module_init(hello_init);
 module_exit(hello_exit);