getpid and getuid nonzero for root

0

I have the following problem. When running:

void main(void){
uid_t getuid(void);
gid_t getgid(void);

uid_t user_id;
gid_t group_id;

printf("user_id: %d\n",user_id);
printf("group_id: %d\n",group_id);
exit(0);
}

I have a return:

user_id: 134513819,group_id: -1216946176.

It was not to return

user_id: 0,group_id: 0.

Given that the file belongs to root and is running as root.

    
asked by anonymous 24.04.2016 / 20:15

1 answer

3

You seem to be declaring functions (not calling) on the first two lines, and then you are declaring two variables without throwing any value on them, so of course they will contain random values.

You would have to do something like

user_id = getuid();

If the compiler complains that the function does not exist,

#include <unistd.h>
#include <sys/types.h>

at the beginning of the program (it was not clear if you had this or not).

    
24.04.2016 / 20:28