在Linux内核中检索会话ID(内核空间) [英] Retrieving session Id in linux kernel (Kernel Space)

查看:165
本文介绍了在Linux内核中检索会话ID(内核空间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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.

推荐答案

您可以在此处查看getsid系统调用:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆