指定授權方式
沒有透過Module_LICENSE聚集指定授權方式的話,在載入驅動程式的時候就會顯示警告訊息,但不會拒絕載入程式。 訊息如下顯示:
Warning: loading xxxxxx.ko will taint the kernel: no license
很顯然這訊息是要您在 kernel module 裡面加上版權宣告,例如:”GPL”,”GPL v2″…等來宣告您的 module 並非 open source,利用 MODULE_LICENSE() 巨集來宣告程式 License,同樣的,可以用 MODULE_DESCRIPTION() 來描述此模組或者是 Driver 的功用跟簡介,以及用 MODULE_AUTHOR() 來定義此模組作者,這些巨集都可以在 linux/module.h 裡找到。
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
static int __init hello_init(void)
{
pr_info("Hello, world appleboy\n");
pr_info("The process is \"%s\" (pid %i)\n", current->comm, current->pid);
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_INFO "Goodbye\n");
}
MODULE_DESCRIPTION("Hello World !!");/* 此程式介紹與描述*/
MODULE_AUTHOR("Bo-Yi Wu <appleboy.tw at="" gmail.com="">");/* 此程式作者*/
MODULE_LICENSE("GPL");/* 程式 License*/
module_init(hello_init);
module_exit(hello_exit);
在 linux/module.h 裡頭,可以找到 MODULE_LICENSE 可定義的 License
* software modules
*
* "GPL" [GNU Public License v2 or later]
* "GPL v2" [GNU Public License v2]
* "GPL and additional rights" [GNU Public License v2 rights and more]
* "Dual BSD/GPL" [GNU Public License v2
* or BSD license choice]
* "Dual MIT/GPL" [GNU Public License v2
* or MIT license choice]
* "Dual MPL/GPL" [GNU Public License v2
* or Mozilla license choice]
*
* The following other idents are available
*
* "Proprietary" [Non free products]
*
* There are dual licensed components, but when running with Linux it is the
* GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
* is a GPL combined work.
*
* This exists for several reasons
* 1. So modinfo can show license info for users wanting to vet their setup
* is free
* 2. So the community can ignore bug reports including proprietary modules
* 3. So vendors can do likewise based on their own policies
*/