summaryrefslogtreecommitdiff
path: root/sys/src/libc
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-12-19 15:15:38 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2020-12-19 15:15:38 +0100
commit672cf179a1a8a17a4a977eeada60a035a27ed98d (patch)
treef179313e163c1c9f9dad59251cd05cd31e1f560b /sys/src/libc
parentd919ad3b5e8e98d7470275d724772de221e060f6 (diff)
libc: implement getppid() reading /proc/$pid/ppid instead of /dev/ppid
The devcons driver is really the wrong place to serve per process information.
Diffstat (limited to 'sys/src/libc')
-rw-r--r--sys/src/libc/9sys/getppid.c17
1 files changed, 9 insertions, 8 deletions
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);
}