[英]in kernel program get root user id and compare with current user id
As we know, the root uid is 0. so I tried to compare current process uid with 0. as follows: 众所周知,根uid为0。因此,我尝试将当前进程uid与0进行比较。如下所示:
uid_eq(get_current_cred()->uid, 0)
however, I get incompatible type for argument 2 of 'uid_eq' 但是,我得到'uid_eq'的参数2的类型不兼容
I have also tried 我也尝试过
uid_eq(get_current_cred()->uid, (kuid_t)0)
but this also give this error: conversion to non-scalar type requested 但这也会产生此错误:要求转换为非标量类型
How should I check if the current process is root in kernel? 我应该如何检查当前进程是否在内核中是root? Thank you.
谢谢。
kuid_t
is a struct, so you should declare one, and set it's val
member to 0
. kuid_t
是一个结构,因此您应该声明一个,并将其val
成员设置为0
。
Try this 尝试这个
kuid_t rootUid;
rootUid.val = 0;
uid_eq(get_current_cred()->uid, rootUid);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.