From a609c1a2f8d58d21727c13970725445ce4d2f6fa Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 8 Mar 2020 14:11:23 +0100 Subject: [PATCH] devproc: return process id when reading /proc/n/ctl file allow reading the control file of a process and return its pid number. if the process has exited, return an error. this can be usefull as a way to test if a process is still alive. and also makes it behave similar to network protocol directories. another side effect is that processes who erroneously open the ctl file ORDWR would be allowed todo so as along as they have write permission and the process is not a kernel process. --- sys/src/9/port/devproc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sys/src/9/port/devproc.c b/sys/src/9/port/devproc.c index b2f6ebf91..ec630306f 100644 --- a/sys/src/9/port/devproc.c +++ b/sys/src/9/port/devproc.c @@ -442,6 +442,7 @@ procopen(Chan *c, int omode0) error(Eperm); break; + case Qctl: case Qargs: case Qwait: case Qnoteid: @@ -458,11 +459,6 @@ procopen(Chan *c, int omode0) pid = p->noteid; break; - case Qctl: - if(p->kp || omode != OWRITE) - error(Eperm); - break; - case Qmem: case Qregs: case Qfpregs: @@ -946,6 +942,9 @@ procread(Chan *c, void *va, long n, vlong off) } error(Ebadarg); + case Qctl: + return readnum(offset, va, n, p->pid, NUMSIZE); + case Qnoteid: return readnum(offset, va, n, p->noteid, NUMSIZE);