SIGTERM is now a thing but there's no use of it

This commit is contained in:
minjaesong
2021-04-23 14:24:15 +09:00
parent 6902cb27ec
commit 04cafea3c5
3 changed files with 43 additions and 14 deletions

View 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();

View File

@@ -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
var _TVDOS = {};
_TVDOS.VERSION = "1.0";
@@ -127,20 +143,24 @@ var GL = eval(filesystem.readAll("A"));
// @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.
// for command line 'echo foo bar', args[0] must be 'echo'
// @return status returned by the program
var execApp = (cmdsrc, args) => {
var execAppPrg = eval(
`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;` +
`var _appStub=function(exec_args){${cmdsrc}
};try {_appStub;}
catch (e){
if (e instanceof InterruptedException) 'SIGTERM';
else 1;
}`); // making 'exec_args' a app-level global
`var _appStub=function(exec_args){${cmdsrc}\n};_appStub`); // 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;
}
}
///////////////////////////////////////////////////////////////////////////////

View File

@@ -386,7 +386,7 @@ shell.execute = function(line) {
sendLcdMsg(_G.shellProgramTitles[_G.shellProgramTitles.length - 1]);
//serial.println(_G.shellProgramTitles);
return (ret == undefined) ? 0 : ret;
return ret;
}
}
}
@@ -457,8 +457,14 @@ if (goInteractive) {
try {
errorlevel = 0; // reset the number
errorlevel = shell.execute(cmdbuf);
//if (isNaN(errorlevel)) errorlevel = 2;
serial.printerr(`errorlevel: ${errorlevel}`);
let rawE = 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) {
printerrln("\n"+(e.stack || e));