process manager pt2 and vfs remove()

This commit is contained in:
Lisa Milne 2023-11-15 17:27:56 +10:00
parent f9326399c1
commit 95dfb9b684

View file

@ -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')