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

@@ -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;
}
}
///////////////////////////////////////////////////////////////////////////////