0
votes

Using the process defined in struct task_struct http://lxr.linux.no/linux+v2.6.30.5/include/linux/sched.h#L246 how do I get the current user? I have to check if the user is root. I apparently can't use getuid

3
What do you intend to do? Do you have any code you can show?bash.d

3 Answers

2
votes

You can use task_uid to get the user id of the task_struct, or task_euid if that's what you happen to need.

0
votes

Try getlogin_r() function. It is defined in unistd.h and returns the username. Have a look at man getlogin_r for other options.

int getlogin_r(char *buf, size_t bufsize);
0
votes

ended up using a member variable uid_t uid, which I didn't see at first. Checked the version of linux I was using (old) and found it here: http://lxr.linux.no/linux+v2.6.18/include/linux/sched.h#L246

sorry for the trouble