From 95dfb9b684a37e57260e26bba08a111ed32e1baa Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Wed, 15 Nov 2023 17:27:56 +1000 Subject: [PATCH] process manager pt2 and vfs remove() --- clite/core.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/clite/core.js b/clite/core.js index ab1af1a..b7470d5 100644 --- a/clite/core.js +++ b/clite/core.js @@ -417,7 +417,9 @@ clite.proc = { func:fn }); data.procs.push(proc); - // TODO: insert data in /proc/pid + vfsapi.mkFile('/proc/'+proc.pid); + var n = vfsapi.getNode('/proc/'+proc.pid); + n.data.content = 'command: '+proc.command+'\npid: '+proc.pid; return proc.pid; } clite.proc.exit = function(pid) { @@ -428,7 +430,7 @@ clite.proc = { if (!proc) return false; data.procs.splice(i,1); - // TODO: remove data from /proc/pid + vfsapi.remove('/proc/'+pid); return true; } clite.proc.count = function() { @@ -989,14 +991,28 @@ clite.vfs = { return false; } vfsdata.api.remove = function(path) { - // TODO: remove vfs node - return false; + var n = vfsdata.api.getNode(path); + if (!n || (n.data.isdir && n.data.content.length > 0)) + return false; + var dir = clite.lib.dirname(path); + var parent = vfsdata.api.getNode(dir); + if (!parent) + return false; + var c = []; + parent.data.content.forEach(function(nn) { + if (nn == n) + return; + c.push(nn); + }); + parent.data.content = c; + return true; } // make some directories vfsdata.api.mkDir('/bin'); vfsdata.api.mkDir('/dev'); vfsdata.api.mkDir('/etc'); + vfsdata.api.mkDir('/proc'); vfsdata.api.mkDir('/usr'); vfsdata.api.mkDir('/usr/clite'); vfsdata.api.mkDir('/usr/clite/web'); @@ -1256,7 +1272,8 @@ clite.shell = { clite.shell.reading.buff = e.target.value; } }, - exit:function(v) { + exit:function(pid,v) { + clite.proc.exit(pid); if (clite.term.tty.data != null) clite.term.api.closeTTY(clite.term.tty.data); clite.shell.prompt.pop(); @@ -1301,6 +1318,11 @@ clite.shell = { return; } + var pid = clite.proc.add(args.join(' '),fd.node.data.content); + io.exit = function(v) { + clite.shell.exit(pid,v); + } + var r = clite.core.execSafe(function() { var rr = fd.node.data.content(args,Object.create(clite.shell.env),io); if (typeof rr == 'number')