共计 2760 个字符,预计需要花费 7 分钟才能阅读完成。
开始这个计划源于一个 Linux kernel challenge. 网址为:
http://eudyptula-challenge.org/
想要参加的朋友可以发送电子邮件报名参加。 以下是我的第一个任务内容:
This is Task 01 of the Eudyptula Challenge------------------------------------------Write a Linux kernel module, and stand-alone Makefile, that when loadedprints to the kernel debug log level, "Hello World!" Be sure to makethe module unloadable as well.The Makefile should build the kernel module against the source for thecurrently running kernel, or, use an environment variable to specifywhat kernel tree to build it against.Please show proof of this module being built, and running, in yourkernel. What this proof is is up to you. I'm sure you can come up withsomething. Also be sure to send the kernel module you wrote, along withthe Makefile you created to build the module.Remember to use your ID assigned in the Subject: line when responding tothis task, so that I can figure out who to attribute it to. You canjust respond to the task with the answers and all should be fine.If you forgot, your id is "xxxxxxxxxx". But of course you have notforgotten that yet, you are better than that.
好了,开始我的 Task1:hello world! 用 VIM 新建 hello.c
#include <linux/module.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("chin,chenqiin@gmail.com");
MODULE_DESCRIPTION("Task 01 of the Eudyptula Challenge");
MODULE_LICENSE("GPL");
MODULE_VERSION("Version-0.0.2");
static int hello_init(void)
{printk(KERN_DEBUG"Hello,world!\n");
return 0;
}
static void hello_exit(void)
{printk(KERN_DEBUG"Hello exit!\n");
}
module_init(hello_init);
module_exit(hello_exit);
创建一个 Makefile
#Change KDIR to your kernel src
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
obj-m := hello.o
all:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
执行 make 命令就会看到生成一个 hello.ko 的文件:
执行加载:
insmod hello.ko
可以输入如下命令查看模块是否已经加载:
lsmod | grep hello
此时因为是调试级别,所以你查看 /var/log/messages 文件时,会看不到有消息输出。
此时牵涉到的知识有内核日志级别优先级问题了,网上查了下资料,其日志级别宏定义如下:
printk 有 8 个 loglevel, 定义在 <linux/kernel.h> 中:
#define KERN_EMERG "<0>" /* system is unusable */
#define KERN_ALERT "<1>" /* action must be taken immediately */
#define KERN_CRIT "<2>" /* critical conditions */
#define KERN_ERR "<3>" /* error conditions */
#define KERN_WARNING "<4>" /* warning conditions */
#define KERN_NOTICE "<5>" /* normal but significant condition */
#define KERN_INFO "<6>" /* informational */
#define KERN_DEBUG "<7>" /* debug-level messages */只有当 printk 打印信息时的 loglevel 小于 console loglevel 的值(优先级高于 console loglevel),这些信息才会被打印到 console 上。
改变 console loglevel 的方法有如下几种:
1. 启动时 Kernel boot option:loglevel=level
2. 运行时 Runtime: dmesg -n level
(注意:demsg -n level 改变的是 console 上的 loglevel,dmesg 命令仍然会打印出所有级别的系统信息。)
3. 运行时 Runtime: echo $level > /proc/sys/kernel/printk
此时再次查看 dmesg 信息
dmesg | tail -n 2
可以采用以下命令执行卸载:
rmmod hello

人家说了啊,要用纯文本发送邮件,不能用html格式发送
請問你怎麼用gmail 加入的 我用gmail都會被reject 因為HTML format
学习了,顶果子!