各位,我在編譯核心模組時有一個錯誤調了很久也沒解決,請那位仁兄幫忙看看,
666 static __init int cbac_init(void)
667 {
668 struct cred *cred;
669
670 if (!security_module_enable(&cbac_ops))
671 return 0;
672
673 printk(KERN_INFO "cbac: InitializE ");
674 /*
675 * Set the security state for the initial task.
676 */
677 cred = (struct cred *) current->cred;
678 cred->security = &c_f_key.cbackey;
679
680 /*register new key */
681 // if (register_key_type(struct key_type *ckey))
682 // printk(KERN_INFO "CBACKEY INITIALIZED");
683 /* Register with LSM*/
684 if (register_security(&cbac_ops))
685 panic("cbac: Unable to register with kernel.\n");
686
687 return 0;
688 }
689
690 /*cbac requires early initialization in order to label
691 * all processes and objects when they are created.
692 */
693 security_initcall(cbac_init);
調試結果:
security/cbac/cbac_lsm.c:665:20: 錯誤:函數‘cbac_init’儲存類無效
security/cbac/cbac_lsm.c:693:1: 錯誤:初始值設定元素不是常量
security/cbac/cbac_lsm.c:693:1: 錯誤:expected declaration or statement at end of input
就是一個核心模組註冊和初始化函數,是仿照原始碼裡面的現有函數寫的
函數體裡面可以不看,主要就是666 和693行出錯
函數‘cbac_init’儲存類無效,將static關鍵字去掉會消除這個報錯,但是問題還是得不到解決,
源碼加了 static關鍵字就沒事,我這裡就報錯,不知道為什麼
最可恨的還是 666行的__init(宏) 和693行的 security_initcall,一層層往下追最後還是沒有弄清這兩個函數
查這兩個函數可以到這個網址 lxr.linux.no/#linux+v2.6.39/ 有搜尋欄
請朋友幫忙消除第二行報錯。謝了!