diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-12-23 02:31:28 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-12-23 02:31:28 +0100 |
commit | dced7255ec86587b441dc2ac04a8fb268ac5b920 (patch) | |
tree | a5e5a37ea4729605a200cc7659d720a80802e1d6 /sys/src/libc/9sys | |
parent | 2e6a5e704646109a7aaf7dd5a9d3a64475fd0055 (diff) |
libc: re-implement getuser() by stating /proc/$pid/status
The idea is to avoid the magic files that contain
per process information in devcons when possible.
It will make it easier to deprecate them in the future.
Diffstat (limited to 'sys/src/libc/9sys')
-rw-r--r-- | sys/src/libc/9sys/getuser.c | 17 | ||||
-rw-r--r-- | sys/src/libc/9sys/mkfile | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/sys/src/libc/9sys/getuser.c b/sys/src/libc/9sys/getuser.c new file mode 100644 index 000000000..487a88aaf --- /dev/null +++ b/sys/src/libc/9sys/getuser.c @@ -0,0 +1,17 @@ +#include <u.h> +#include <libc.h> + +char * +getuser(void) +{ + static char user[64]; + char name[32]; + Dir *dir; + + snprint(name, sizeof(name), "/proc/%lud/status", (ulong)getpid()); + if((dir = dirstat(name)) == nil) + return "none"; + snprint(user, sizeof(user), "%s", dir->uid); + free(dir); + return user; +} diff --git a/sys/src/libc/9sys/mkfile b/sys/src/libc/9sys/mkfile index 686a7bd49..fe581f14b 100644 --- a/sys/src/libc/9sys/mkfile +++ b/sys/src/libc/9sys/mkfile @@ -24,6 +24,7 @@ OFILES=\ getenv.$O\ getpid.$O\ getppid.$O\ + getuser.$O\ getwd.$O\ idn.$O\ iounit.$O\ |