【Kernel】如何从kernel中获取cred结构体中的value

获取linux kernel cred结构体中成员变量的value时,根绝kernel版本需要做适配。

linux kernel 3.5以上,获取cred需要如下处理(重点 cred->uid.val):

       #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
        printk(KERN_INFO "PROCESS cred info: uid %u ",
                                cred->uid.val);
        #else
        printk(KERN_INFO "PROCESS cred info: uid %u",
                                cred->uid);
        #endif

否则报错:

xxx.c: In function ‘xxxxxxx’:
./include/linux/kern_levels.h:5:18: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘kuid_t {aka const struct }’ [-Wformat=]
 #define KERN_SOH "\001"  /* ASCII Start Of Header */
                  ^
./include/linux/kern_levels.h:14:19: note: in expansion of macro ‘KERN_SOH’
 #define KERN_INFO KERN_SOH "6" /* informational *

 

 

你可能感兴趣的:(Kernel)