clean up reboot code a bit, add help to reboot command

This commit is contained in:
Lisa Milne 2023-11-14 14:53:45 +10:00
parent d8570be0f2
commit f9326399c1
2 changed files with 48 additions and 12 deletions

View file

@ -492,6 +492,31 @@ Options:
clite.commands.load('reboot',function(args,env,io) {
var stdio = io.include('stdio');
function help() {
io.write(`
reboot - reboot the system, forcing reload of all code
Options:
-? Print this help information
`);
}
for (var i=1; i<args.length; i++) {
if (args[i][0] == '-') {
for (var j=1; j<args[i].length; j++) {
switch (args[i][j]) {
case '?':
help();
return 0;
break;
default:
io.error('unknown argument: -'+args[i][j]);
}
}
}else{
io.error('unknown argument: '+args[i]);
}
}
var fd = stdio.open('/dev/initctl',false);
if (!fd)

View file

@ -1,5 +1,6 @@
var clite = {
state:{
version:'0.1-12',
isinit:false,
terminal:null,
input:{
@ -94,6 +95,23 @@ var clite = {
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
},
reboot:function() {
clite.log.write('The system is rebooting');
setTimeout(function() {
clite.term.preventInput();
clite.log.write('Bringing down the system');
var l = clite.core.load.script;
var s = Array.from(document.getElementsByTagName('src'));
s.forEach(function(el,i) {
el.parentNode.removeChild(el);
});
clite.term.preventInput();
clite.log.write('Resetting system core');
delete clite;
clite = null;
l('clite/core.js',function() {setTimeout('clite.init();',500)});
},10);
}
},
init:function() {
@ -191,21 +209,13 @@ var clite = {
n.data.content.data = 1;
break;
case 3: // really just a status change, doesn't "do" anything
clite.init = 3;
n.data.content.data = 3;
break;
case 6:
clite.init = 6;
n.data.content.data = 6;
setTimeout(function() {
var l = clite.core.load.script;
var s = Array.from(document.getElementsByTagName('src'));
s.forEach(function(el) {
el.parentNode.removeChild(el);
});
clite.term.preventInput();
delete clite;
clite = null;
l('clite/core.js',function() {setTimeout('clite.init();',10)});
},10);
clite.core.reboot();
break;
default:;
}
@ -218,6 +228,7 @@ var clite = {
}
function init1() {
clite.log.write('CLIte Version '+clite.state.version);
// setup vfs
clite.log.write('Setting up VFS');
clite.vfs.init();
@ -1007,7 +1018,7 @@ clite.vfs = {
clite.log = {
init:function(vfs) {
clite.log.write = function(txt) {
if (!clite.user.hasLogin()) {
if (!clite.user.hasLogin() || (typeof clite.init == 'number' && clite.init != 3)) {
try {
clite.term.writeLine(txt);
} catch(e) {}