a bunch of little fixes

This commit is contained in:
Lisa Milne 2023-12-18 21:44:02 +10:00
parent 733ee75dd2
commit fe972ddd11
4 changed files with 61 additions and 31 deletions

View file

@ -101,6 +101,12 @@ var bios = {
bios.input.upload.data.callback = d.fn;
bios.input.upload.data.file = d.file;
bios.input.setState(2);
break;
case 4:
bios.boot.shutdown(!d);
if (d == true)
setTimeout(bios.boot.reboot,10);
break;
default:;
}
},
@ -250,6 +256,20 @@ var bios = {
bios.core.writeStringVGA(1,7,'Error in bootable entry point',4);
bios.core.writeStringVGA(1,8,err.message,6);
}
},
shutdown:function(complete) {
var s = Array.from(document.getElementsByTagName('src'));
s.forEach(function(el,i) {
if (i>0)
el.parentNode.removeChild(el);
});
if (!complete)
return;
document.body.innerHTML = 'The system has shutdown';
bios = null;
},
reboot:function() {
setTimeout(bios.boot.preBoot,1000);
}
},
init:function() {

View file

@ -3,10 +3,6 @@ clite.commands.data = function() {
clite.commands.load('help',function(args,env,io) {
var stdio = io.include('stdio');
if (args.length > 1) {
// TODO: implement command help lookup
stdio.printf('help with arguments is a work in progress\n');
}
stdio.printf(`
Welcome to CLIte (pronounced like 'site' with an added L).
@ -133,24 +129,23 @@ Options:
dirs.forEach(function(dir,index) {
if (dirs.length > 1)
stdio.printf('%s:\n',dir);
var fd = stdio.open(dir,stdio.flags.O_RDONLY|stdio.flags.O_SYNC);
if (!fd) {
stdio.fprintf(io.stderr,'cannot open directory: %s\n',dir);
return;
}
var st = stdio.fstatat(fd,stdio.flags.AT_SYMLINK_NOFOLLOW);
var st = stdio.lstat(dir);
if (!st) {
stdio.fprintf(io.stderr,'cannot read file: %s\n',dir);
stdio.close(fd);
return;
}
if (st.type != stdio.types.FT_DIR) {
writeNodeData(st,fd);
stdio.close(fd);
writeNodeData(st,dir);
if (!one && !long)
stdio.write(io.stdout,'\n');
return;
}
var fd = stdio.open(dir,stdio.flags.O_RDONLY|stdio.flags.O_SYNC);
if (!fd) {
stdio.fprintf(io.stderr,'cannot open directory: %s\n',dir);
return;
}
var e;
while ((e = stdio.read(fd)) != null) {
if (e[0] == '.' && !all)

View file

@ -57,33 +57,24 @@ var clite = {
},
reboot:function() {
clite.log.write('The system is rebooting');
// TODO: this all needs redoing with bios calls
setTimeout(function() {
clite.log.write('Bringing down the system');
var s = Array.from(document.getElementsByTagName('src'));
s.forEach(function(el,i) {
if (i>0)
el.parentNode.removeChild(el);
});
clite.console.clear();
clite.log.write('Bringing down the system');
clite.log.write('Resetting system core');
var b = clite.state.bios;
delete clite;
clite = null;
setTimeout(b.boot.preBoot,100);
b.io.write(4,true);
},10);
},
shutdown:function() {
clite.log.write('The system is shutting down');
// TODO: this all needs redoing with bios calls
setTimeout(function() {
var s = Array.from(document.getElementsByTagName('src'));
s.forEach(function(el) {
el.parentNode.removeChild(el);
});
clite.console.clear();
clite.log.write('Bringing down the system');
delete clite;
clite = null;
b.io.write(4,false);
},10);
},
hostname:function() {
@ -898,6 +889,34 @@ clite.user = {
}]
};
var env = {};
function getNextUid() {
let id = data.users.length;
let accepted = false;
while (!accepted) {
accepted = true;
for (var i=0; i<data.users.length; i++) {
if (data.users[i].uid == id)
accepted = false;
}
if (!accepted)
id++;
}
return id;
}
function getNextGid() {
let id = data.groups.length;
let accepted = false;
while (!accepted) {
accepted = true;
for (var i=0; i<data.groups.length; i++) {
if (data.groups[i].gid == id)
accepted = false;
}
if (!accepted)
id++;
}
return id;
}
function getUser(uid) {
for (var i=0; i<data.users.length; i++) {
if (data.users[i].uid == uid)
@ -1145,8 +1164,7 @@ cat -l /usr/share/introduction
var udata = {};
udata.name = pw.pw_name;
udata.pass = 'x';
// TODO: this could cause 2 users with the same uid
udata.uid = data.users.length;
udata.uid = getNextUid();
udata.gid = pw.pw_gid;
udata.groups = [];
udata.env = {};
@ -1236,8 +1254,7 @@ cat -l /usr/share/introduction
return false;
var gdata = {};
gdata.name = gr.gr_name;
// TODO: this could cause 2 groups with the same gid
gdata.gid = data.groups.length;
gdata.gid = getNextGid();
gdata.users = Array.from(gr.gr_mem);
data.groups.push(gdata);
saveUsers();

View file

@ -947,7 +947,6 @@ Options:
});
}
}else if (a != '') {
// TODO: path fill
let p = clite.resolvePath(a);
if (p[0] == '/') {
let d = stdlib.dirname(p);
@ -1099,7 +1098,6 @@ Options:
}
}
// TODO: hacks r uglee
// if args[0] isn't the shell itself, then we're running a shell script
if (!f && args[0] != '/bin/sh' && args[0] != 'sh') {
f = clite.resolvePath(args[0]);