mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-26 21:23:21 +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:
@@ -862,12 +862,31 @@ int wmain(int argc, char* wargv[])
|
|||||||
#endif
|
#endif
|
||||||
#ifndef _MINCORE
|
#ifndef _MINCORE
|
||||||
else if (argc > 1 && memcmp(argv[1], "-update:", 8) == 0)
|
else if (argc > 1 && memcmp(argv[1], "-update:", 8) == 0)
|
||||||
{
|
{
|
||||||
// Attempt to copy our own exe over the original exe
|
char *update = ILibMemory_Allocate(512, 0, NULL, NULL);
|
||||||
while (util_CopyFile(argv[0], argv[1] + 8, FALSE) == FALSE) Sleep(5000);
|
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
|
//// Attempt to copy our own exe over the original exe
|
||||||
LaunchService(serviceFile);
|
//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))
|
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);
|
int pid = duk_require_int(ctx, 0);
|
||||||
|
|
||||||
#ifdef WIN32
|
#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)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
duk_eval_string(ctx, ILibScratchPad); // [child_process]
|
duk_eval_string(ctx, ILibScratchPad); // [child_process]
|
||||||
|
|||||||
@@ -406,4 +406,52 @@ module.exports =
|
|||||||
{
|
{
|
||||||
fullInstall: fullInstall,
|
fullInstall: fullInstall,
|
||||||
fullUninstall: fullUninstall
|
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