在Linux内核中检索会话ID(内核空间) [英] Retrieving session Id in linux kernel (Kernel Space)
问题描述
我想在linux内核(内核空间)中检索当前进程的sessionid.我看到task_struct
具有字段sessionid
,但仅在宏CONFIG_AUDITSYSCALL
处于ON时定义.所以我试图用这个宏打开内核,但是仍然没有得到结果.我也尝试从audit_get_sessionid(current)
上的CONFIG_AUDITSYSCALL
函数获取其值,但得到-1或垃圾值(与用户空间中的getsid(0)
方法不同).
I want to retrieve the sessionid of the current process in linux kernel (Kernel Space). I saw task_struct
has a field sessionid
but it is defined only when the macro CONFIG_AUDITSYSCALL
is ON. So i tried to build the kernel with this macro ON but still i was not getting the result. Also I tried getting its value from function with CONFIG_AUDITSYSCALL
on audit_get_sessionid(current)
but was getting either -1 or junk value ( different from getsid(0)
method in user space).
这时我很震惊.任何建议都会有很大帮助.
I am struck at this point. Any suggestion would be of great help.
推荐答案
You can take a look at the getsid
syscall at here: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=kernel/sys.c#l1106
SYSCALL_DEFINE1(getsid, pid_t, pid)
{
struct task_struct *p;
struct pid *sid;
int retval;
rcu_read_lock();
if (!pid)
sid = task_session(current);
else {
...
建议您可以使用内核函数task_session()获取会话ID.
Which suggest you can use the kernel function task_session() to get the session id.
这篇关于在Linux内核中检索会话ID(内核空间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!