summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/plan9/getppid.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2012-12-03 05:35:33 +0100
committercinap_lenrek <cinap_lenrek@gmx.de>2012-12-03 05:35:33 +0100
commiteb9de925c63990f6b19494698e4db1eb9682e46d (patch)
tree774c129eaad9c5e0e8922885f9d310c8d6863e22 /sys/src/ape/lib/ap/plan9/getppid.c
parentf3842de5fd405859f0a2de9a6f9fed0311c4629c (diff)
ape: fix more bugs, use /env and /proc instead of #e and #p, cleanup
remove envname length limitation in _envsetup() by using allocated buffer and use /env instead of #e use /proc and getpid() instead of #p and #c in readprocfdinit() fix buffer overflow in execlp(), check if name of failed exec starts with / . or is \0 make sure not to close our own filedescriptors for FD_CLOEXEC in execve(), fix wrong length check for flushing buffer to /env/_fdinfo. fix error handling cases. copy the enviroment before decoding \1 to \0 because the strings in environ[] array might not be writable. remove bogus close if we fail to open ppid file in getppid() and use /dev/ppid instead of #c/ppid
Diffstat (limited to 'sys/src/ape/lib/ap/plan9/getppid.c')
-rw-r--r--sys/src/ape/lib/ap/plan9/getppid.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/sys/src/ape/lib/ap/plan9/getppid.c b/sys/src/ape/lib/ap/plan9/getppid.c
index 01759221b..6d40a3cc9 100644
--- a/sys/src/ape/lib/ap/plan9/getppid.c
+++ b/sys/src/ape/lib/ap/plan9/getppid.c
@@ -9,15 +9,14 @@
pid_t
getppid(void)
{
- int n, f;
- char ppidbuf[15];
+ char b[20];
+ int f;
- f = open("#c/ppid", 0);
- n = read(f, ppidbuf, sizeof ppidbuf);
- if(n < 0)
- errno = EINVAL;
- else
- n = atoi(ppidbuf);
- close(f);
- return n;
+ memset(b, 0, sizeof(b));
+ f = open("/dev/ppid", 0);
+ if(f >= 0) {
+ read(f, b, sizeof(b));
+ close(f);
+ }
+ return atol(b);
}