From f90a77c42a3d924e0ffc01ddfca1d677ee2866da Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Sat, 11 Nov 2023 22:06:50 +1000 Subject: [PATCH] process manager pt1 --- clite/core.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/clite/core.js b/clite/core.js index 10a581a..9027a6c 100644 --- a/clite/core.js +++ b/clite/core.js @@ -217,6 +217,11 @@ data/about.txt:/usr/share/site/about:0:0:-rw-rw-r--`; function init3(data) { clite.core.execSafe(clite.commands.data); clite.commands = null; + clite.log.write('Bringing up the process manager'); + if (!clite.proc.init(vfsapi)) { + clite.log.write('failed'); + return; + } // check cookies for login clite.log.write('Checking for user session'); if (clite.user.init(vfsapi)) {// if logged in: @@ -262,6 +267,67 @@ data/about.txt:/usr/share/site/about:0:0:-rw-rw-r--`; } }; +clite.proc = { + init:function(vfs) { + var vfsapi = vfs; + var data = { + nextid:1, + procs:[] + }; + + function getProc(pid) { + var proc = null; + data.procs.forEach(function(p,i) { + if (proc) + return; + if (p.pid == pid) + proc = p; + }); + return proc; + } + function getProcIndex(pid) { + var index = -1; + data.procs.forEach(function(p,i) { + if (index > -1) + return; + if (p.pid == pid) + index = i; + }); + return index; + } + + clite.proc.add = function(cl,fn) { + var proc = Object.create({ + pid:data.nextid++, + command:cl, + func:fn + }); + data.procs.push(proc); + // TODO: insert data in /proc/pid + return proc.pid; + } + clite.proc.exit = function(pid) { + var i = getProcIndex(pid); + if (i<0) + return false; + var proc = getProc(pid); + if (!proc) + return false; + data.procs.splice(i,1); + // TODO: remove data from /proc/pid + return true; + } + clite.proc.count = function() { + return data.procs.length; + } + clite.proc.init = null; + return true; + }, + add:function(cl,fn) {return 0;}, + exit:function(id) {}, + count:function() {return 0;} +}; + clite.user = { init:function(vfs) { // returns true if there's a user login or false for guest var udata = {