mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
process manager pt1
This commit is contained in:
parent
04a4b8ed87
commit
f90a77c42a
1 changed files with 66 additions and 0 deletions
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue