summaryrefslogtreecommitdiff
path: root/sys/src/ape
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/ape
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/ape')
-rw-r--r--sys/src/ape/lib/ap/plan9/getppid.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/sys/src/ape/lib/ap/plan9/getppid.c b/sys/src/ape/lib/ap/plan9/getppid.c
index ad38e2c7b..d4cd710c2 100644
--- a/sys/src/ape/lib/ap/plan9/getppid.c
+++ b/sys/src/ape/lib/ap/plan9/getppid.c
@@ -1,6 +1,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -9,14 +10,15 @@
pid_t
getppid(void)
{
- char b[20];
+ char buf[32];
int f;
- memset(b, 0, sizeof(b));
- f = _OPEN("/dev/ppid", OREAD);
- if(f >= 0) {
- _PREAD(f, b, sizeof(b), 0);
- _CLOSE(f);
- }
- return atol(b);
+ snprintf(buf, sizeof(buf), "/proc/%d/ppid", getpid());
+ f = open(buf, 0);
+ if(f < 0)
+ return 0;
+ memset(buf, 0, sizeof(buf));
+ read(f, buf, sizeof(buf)-1);
+ close(f);
+ return atol(buf);
}