summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-03-08 14:11:23 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2020-03-08 14:11:23 +0100
commita609c1a2f8d58d21727c13970725445ce4d2f6fa (patch)
treefbfd17e46df3797aa6b290e8a55922a5ae811754
parent57741d473f9d5165d142b165bd837984f6428c66 (diff)
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.
-rw-r--r--sys/src/9/port/devproc.c9
1 files 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);