mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
SIGTERM is now a thing but there's no use of it
This commit is contained in:
3
assets/disk0/returnany.js
Normal file
3
assets/disk0/returnany.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
println("This program attemps to read a string and returns it verbatim. If the underlying shell is not insane, errorlevel must be 0.\nNow, let's put this to the test...");
|
||||||
|
print("Your word? ");
|
||||||
|
return read();
|
||||||
@@ -1,3 +1,19 @@
|
|||||||
|
// define exceptions
|
||||||
|
function InterruptedException(m) {
|
||||||
|
this.message = m;
|
||||||
|
this.stack = (new Error()).stack;
|
||||||
|
};
|
||||||
|
InterruptedException.prototype = Object.create(Error.prototype);
|
||||||
|
InterruptedException.prototype.name = 'InterruptedException';
|
||||||
|
InterruptedException.prototype.constructor = InterruptedException;
|
||||||
|
class SIG {
|
||||||
|
constructor(name, number) {
|
||||||
|
this.name = "SIG" + name;
|
||||||
|
this.number = number|0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const SIGTERM = new SIG("TERM",15);
|
||||||
|
const SIGSEGV = new SIG("SEGV",11)
|
||||||
// define TVDOS
|
// define TVDOS
|
||||||
var _TVDOS = {};
|
var _TVDOS = {};
|
||||||
_TVDOS.VERSION = "1.0";
|
_TVDOS.VERSION = "1.0";
|
||||||
@@ -127,20 +143,24 @@ var GL = eval(filesystem.readAll("A"));
|
|||||||
// @param cmdsrc JS source code
|
// @param cmdsrc JS source code
|
||||||
// @param args arguments for the program, must be Array, and args[0] is always the name of the program, e.g.
|
// @param args arguments for the program, must be Array, and args[0] is always the name of the program, e.g.
|
||||||
// for command line 'echo foo bar', args[0] must be 'echo'
|
// for command line 'echo foo bar', args[0] must be 'echo'
|
||||||
|
// @return status returned by the program
|
||||||
var execApp = (cmdsrc, args) => {
|
var execApp = (cmdsrc, args) => {
|
||||||
var execAppPrg = eval(
|
var execAppPrg = eval(
|
||||||
`function InterruptedException(m){this.message=m;this.stack=(new Error()).stack;};` +
|
`var _appStub=function(exec_args){${cmdsrc}\n};_appStub`); // making 'exec_args' a app-level global
|
||||||
`InterruptedException.prototype=Object.create(Error.prototype);` +
|
|
||||||
`InterruptedException.prototype.name='InterruptedException';` +
|
|
||||||
`InterruptedException.prototype.constructor=InterruptedException;` +
|
|
||||||
`var _appStub=function(exec_args){${cmdsrc}
|
|
||||||
};try {_appStub;}
|
|
||||||
catch (e){
|
|
||||||
if (e instanceof InterruptedException) 'SIGTERM';
|
|
||||||
else 1;
|
|
||||||
}`); // making 'exec_args' a app-level global
|
|
||||||
|
|
||||||
return execAppPrg(args);
|
var status = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
status = execAppPrg(args);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
serial.printerr(`app execution interrupted -- ${e}\n${e.stack}`);
|
||||||
|
if (e instanceof InterruptedException)
|
||||||
|
return SIGTERM;
|
||||||
|
else
|
||||||
|
return (undefined == status) ? 0 : status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ shell.execute = function(line) {
|
|||||||
sendLcdMsg(_G.shellProgramTitles[_G.shellProgramTitles.length - 1]);
|
sendLcdMsg(_G.shellProgramTitles[_G.shellProgramTitles.length - 1]);
|
||||||
//serial.println(_G.shellProgramTitles);
|
//serial.println(_G.shellProgramTitles);
|
||||||
|
|
||||||
return (ret == undefined) ? 0 : ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -457,8 +457,14 @@ if (goInteractive) {
|
|||||||
try {
|
try {
|
||||||
errorlevel = 0; // reset the number
|
errorlevel = 0; // reset the number
|
||||||
errorlevel = shell.execute(cmdbuf);
|
errorlevel = shell.execute(cmdbuf);
|
||||||
//if (isNaN(errorlevel)) errorlevel = 2;
|
let rawE = errorlevel;
|
||||||
serial.printerr(`errorlevel: ${errorlevel}`);
|
|
||||||
|
if (errorlevel instanceof SIG)
|
||||||
|
errorlevel = errorlevel.name;
|
||||||
|
else if (errorlevel == undefined || (typeof errorlevel.trim == "function" && errorlevel.trim().length == 0) || isNaN(errorlevel))
|
||||||
|
errorlevel = 0;
|
||||||
|
|
||||||
|
serial.printerr(`errorlevel: ${errorlevel} (raw: ${rawE})`);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
printerrln("\n"+(e.stack || e));
|
printerrln("\n"+(e.stack || e));
|
||||||
|
|||||||
Reference in New Issue
Block a user