mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-27 13:43:17 +00:00
1. Fixed process.kill() on windows to wait to complete
2. Updated self update on windows to handle stale processes
This commit is contained in:
@@ -863,11 +863,30 @@ int wmain(int argc, char* wargv[])
|
||||
#ifndef _MINCORE
|
||||
else if (argc > 1 && memcmp(argv[1], "-update:", 8) == 0)
|
||||
{
|
||||
// Attempt to copy our own exe over the original exe
|
||||
while (util_CopyFile(argv[0], argv[1] + 8, FALSE) == FALSE) Sleep(5000);
|
||||
char *update = ILibMemory_Allocate(512, 0, NULL, NULL);
|
||||
int updateLen = sprintf_s(update, 512, "require('agent-installer').update();");
|
||||
__try
|
||||
{
|
||||
agent = MeshAgent_Create(0);
|
||||
agent->meshCoreCtx_embeddedScript = update;
|
||||
agent->meshCoreCtx_embeddedScriptLen = updateLen;
|
||||
MeshAgent_Start(agent, argc, argv);
|
||||
retCode = agent->exitCode;
|
||||
MeshAgent_Destroy(agent);
|
||||
agent = NULL;
|
||||
}
|
||||
__except (ILib_WindowsExceptionFilterEx(GetExceptionCode(), GetExceptionInformation(), &winException))
|
||||
{
|
||||
ILib_WindowsExceptionDebugEx(&winException);
|
||||
}
|
||||
wmain_free(argv);
|
||||
return(retCode);
|
||||
|
||||
// Attempt to start the updated service up again
|
||||
LaunchService(serviceFile);
|
||||
//// Attempt to copy our own exe over the original exe
|
||||
//while (util_CopyFile(argv[0], argv[1] + 8, FALSE) == FALSE) Sleep(5000);
|
||||
|
||||
//// Attempt to start the updated service up again
|
||||
//LaunchService(serviceFile);
|
||||
}
|
||||
else if (argc > 1 && (strcasecmp(argv[1], "-netinfo") == 0))
|
||||
{
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -843,7 +843,7 @@ duk_ret_t ILibDuktape_ScriptContainer_Process_Kill(duk_context *ctx)
|
||||
int pid = duk_require_int(ctx, 0);
|
||||
|
||||
#ifdef WIN32
|
||||
int len = sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "require('child_process').execFile(process.env['windir'] + '\\x5Csystem32\\x5Ccmd.exe', ['/C', 'taskkill /F /PID %d']);", pid);
|
||||
int len = sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "require('child_process').execFile(process.env['windir'] + '\\x5Csystem32\\x5Ccmd.exe', ['/C', 'taskkill /F /PID %d']).waitExit();", pid);
|
||||
if (len > 0)
|
||||
{
|
||||
duk_eval_string(ctx, ILibScratchPad); // [child_process]
|
||||
|
||||
@@ -407,3 +407,51 @@ module.exports =
|
||||
fullInstall: fullInstall,
|
||||
fullUninstall: fullUninstall
|
||||
};
|
||||
|
||||
if (process.platform == 'win32')
|
||||
{
|
||||
function win_update()
|
||||
{
|
||||
var fini = setTimeout(function ()
|
||||
{
|
||||
// If this hits, it's becuase something went wrong... So just abort
|
||||
process._exit();
|
||||
}, 20000);
|
||||
|
||||
var updateLocation = process.argv[1].substring(8);
|
||||
var service = null;
|
||||
var serviceLocation = "";
|
||||
|
||||
service = require('service-manager').manager.getService('Mesh Agent');
|
||||
serviceLocation = service.appLocation();
|
||||
|
||||
var t = setTimeout(function ()
|
||||
{
|
||||
service.stop().finally(function ()
|
||||
{
|
||||
require('process-manager').enumerateProcesses().then(function (proc)
|
||||
{
|
||||
for (var p in proc)
|
||||
{
|
||||
if (proc[p].path == serviceLocation)
|
||||
{
|
||||
process.kill(proc[p].pid);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
require('fs').copyFileSync(process.execPath, updateLocation);
|
||||
}
|
||||
catch (ce)
|
||||
{
|
||||
}
|
||||
|
||||
service.start();
|
||||
process._exit();
|
||||
});
|
||||
});
|
||||
}, 3000);
|
||||
}
|
||||
module.exports.update = win_update;
|
||||
}
|
||||
Reference in New Issue
Block a user