shithub: riscv

Download patch

ref: a609c1a2f8d58d21727c13970725445ce4d2f6fa
parent: 57741d473f9d5165d142b165bd837984f6428c66
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Mar 8 10:11:23 EDT 2020

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.

--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -442,6 +442,7 @@
 			error(Eperm);
 		break;
 
+	case Qctl:
 	case Qargs:
 	case Qwait:
 	case Qnoteid:
@@ -458,11 +459,6 @@
 		pid = p->noteid;
 		break;
 
-	case Qctl:
-		if(p->kp || omode != OWRITE)
-			error(Eperm);
-		break;
-
 	case Qmem:
 	case Qregs:
 	case Qfpregs:
@@ -945,6 +941,9 @@
 			}
 		}
 		error(Ebadarg);
+
+	case Qctl:
+		return readnum(offset, va, n, p->pid, NUMSIZE);
 
 	case Qnoteid:
 		return readnum(offset, va, n, p->noteid, NUMSIZE);