9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit d0f313465a85ed49e1d3d8866f70de0f473a0912
parent b1ba512aa22afc8e52a4eb0593b5c8da4d5db276
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date:   Wed, 16 Nov 2022 19:06:19 +0100

os9: Add /proc/cur file

This file always points to the current process.

Diffstat:
Msrc/os9/dev/devproc.c | 40+++++++++++++++++++++++-----------------
1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/src/os9/dev/devproc.c b/src/os9/dev/devproc.c @@ -27,26 +27,32 @@ static int procfsgen(Chan *c, Dirtab *tab, int ntab, int n, Dir *dir) { Task *tp; - int ret = 0; char nam[NAMELEN]; - n = getntask(n, &tp); - if (n <= 0) + switch (n) { + case NR_TASKS: + mkentry(c, dir, + "cur", 0, + QID(CHDIR, 0, PATH(Qtaskdir, proc->tid)), + O_READ); + return 1; + case NR_TASKS+1: return -1; - if (tp->tid == -1) - goto novalid; - - ksnprint(nam, NAMELEN, "%d", tp->tid); - mkentry(c, dir, - nam, 0, - QID(CHDIR, 0, PATH(Qtaskdir, tp->tid)), - O_READ); - ret = 1; - -novalid: - unlock(&tp->m); - - return ret; + default: + n = getntask(n, &tp); + if (n < 0) + return -1; + if (n == 0) + return 0; + + ksnprint(nam, NAMELEN, "%d", tp->tid); + mkentry(c, dir, + nam, 0, + QID(CHDIR, 0, PATH(Qtaskdir, tp->tid)), + O_READ); + unlock(&tp->m); + return 1; + } } static int