From 672cf179a1a8a17a4a977eeada60a035a27ed98d Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 19 Dec 2020 15:15:38 +0100 Subject: libc: implement getppid() reading /proc/$pid/ppid instead of /dev/ppid The devcons driver is really the wrong place to serve per process information. --- sys/src/libc/9sys/getppid.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'sys/src/libc') diff --git a/sys/src/libc/9sys/getppid.c b/sys/src/libc/9sys/getppid.c index 87b878927..1d1fc433f 100644 --- a/sys/src/libc/9sys/getppid.c +++ b/sys/src/libc/9sys/getppid.c @@ -4,14 +4,15 @@ int getppid(void) { - char b[20]; + char buf[32]; int f; - memset(b, 0, sizeof(b)); - f = open("/dev/ppid", OREAD|OCEXEC); - if(f >= 0) { - read(f, b, sizeof(b)); - close(f); - } - return atol(b); + snprint(buf, sizeof(buf), "/proc/%lud/ppid", (ulong)getpid()); + f = open(buf, OREAD|OCEXEC); + if(f < 0) + return 0; + memset(buf, 0, sizeof(buf)); + read(f, buf, sizeof(buf)-1); + close(f); + return atol(buf); } -- cgit v1.2.3