1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-06 00:13:33 +00:00

Fixed bug on Linux Agent, where a service stop, didn't gracefully shutdown the agent. Modified so that SIGTERM is caught, and causes the agent to gracefully shutdown. This change made it so the clipboard cleanup code could correctly run.

This commit is contained in:
Bryan Roe
2022-06-30 01:23:29 -07:00
parent dcd8669746
commit b493da68e4
3 changed files with 26 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@@ -2863,6 +2863,13 @@ void ILibDuktape_PAC_Init(duk_context *ctx)
ILibDuktape_ModSearch_AddHandler(ctx, "PAC", ILibDuktape_PAC_PUSH);
}
duk_ret_t ILibDuktape_ScriptContainer_SIGTERM_HANDLER(duk_context *ctx)
{
void *chain = duk_ctx_chain(ctx);
ILibStopChain(chain);
return(0);
}
duk_context *ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx3(duk_context *ctx, SCRIPT_ENGINE_SECURITY_FLAGS securityFlags, unsigned int executionTimeout, void *chain, char **argList, ILibSimpleDataStore *db, char *exePath, ILibProcessPipe_Manager pipeManager, ILibDuktape_HelperEvent exitHandler, void *exitUser)
{
void **timeoutKey = executionTimeout > 0 ? (void**)ILibMemory_Allocate(sizeof(void*), 0, NULL, NULL) : NULL;
@@ -2962,6 +2969,16 @@ duk_context *ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx3(duk_conte
ILibDuktape_Polyfills_JS_Init(ctx);
ILibDuktape_Polyfills_promise_wait(ctx);
#ifdef _POSIX
int tp = duk_get_top(ctx);
duk_eval_string(ctx, "process"); // [process]
duk_prepare_method_call(ctx, -1, "on"); // [process][on][this]
duk_push_string(ctx, "SIGTERM"); // [process][on][this][SIGTERM]
duk_push_c_function(ctx, ILibDuktape_ScriptContainer_SIGTERM_HANDLER, DUK_VARARGS); // [process][on][this][SIGTERM][func]
duk_pcall_method(ctx, 2);
duk_set_top(ctx, tp);
#endif
return ctx;
}

View File

@@ -400,8 +400,7 @@ function lin_xclip_copy(txt)
ch.stdin.write(' for(i=1;i<NF;++i)');
ch.stdin.write(' {');
ch.stdin.write(' split($i,tokens," ");');
ch.stdin.write(' name=substr($i, length(tokens[1])+2);');
ch.stdin.write(' if(substr(name,1,1)==" ") { name=substr($i, length(tokens[1])+3); }');
ch.stdin.write(' name=tokens[2];');
ch.stdin.write(' chkname=substr(name,1,6);')
ch.stdin.write(' if(chkname=="xclip(")');
ch.stdin.write(' {');
@@ -425,7 +424,12 @@ function lin_xclip_copy(txt)
};
ret.child._cleanup = function _cleanup(p)
{
process.kill(this._xclip_PID, 'SIGKILL');
if (this.cleaned) { return; }
this.cleaned = true;
// During Cleanup, we need to kill the xclip process that was spawned, becuase xclip likes to hang around
console.info1('XCLIP/' + (this._xclip_PID) + ' => SIGKILL');
if (this._xclip_PID > 0) { process.kill(this._xclip_PID, 'SIGKILL'); }
delete xclipTable[p._hashCode()];
};
ret.child.on('exit', function ()
@@ -442,10 +446,7 @@ function lin_xclip_copy(txt)
});
ret.child.on('~', function ()
{
if (xclipTable[this.promise._hashCode()])
{
this._cleanup(this.promise);
}
this._cleanup(this.promise);
});
ret.child._xclip_PID = ret.child._helper(ret);
return (ret);