mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-20 10:13:17 +00:00
1. Updated selfTest for Linux
2. Fixed edge case crash in ILibChain_Continue()
This commit is contained in:
@@ -3987,6 +3987,7 @@ void MeshServer_Agent_SelfTest(MeshAgentHostContainer *agent)
|
||||
if (duk_peval_string(agent->meshCoreCtx, "require('agent-selftest')();") != 0)
|
||||
{
|
||||
printf(" -> Loading Test Script.................[FAILED]\n");
|
||||
exit(1);
|
||||
}
|
||||
duk_pop(agent->meshCoreCtx);
|
||||
}
|
||||
|
||||
@@ -2604,14 +2604,11 @@ duk_ret_t ILibDuktape_Polyfills_promise_wait_impl(duk_context *ctx)
|
||||
|
||||
if (!duk_has_prop_string(ctx, -2, "settled"))
|
||||
{
|
||||
ILibChain_Link **modules = ILibChain_GetModules(duk_ctx_chain(ctx));
|
||||
int count = (int)(ILibMemory_Size(modules) / sizeof(ILibChain_Link*));
|
||||
#ifdef WIN32
|
||||
continueResult = ILibChain_Continue(duk_ctx_chain(ctx), modules, count, timeout, NULL);
|
||||
continueResult = ILibChain_Continue(duk_ctx_chain(ctx), NULL, 0, timeout, NULL);
|
||||
#else
|
||||
continueResult = ILibChain_Continue(duk_ctx_chain(ctx), modules, count, timeout);
|
||||
continueResult = ILibChain_Continue(duk_ctx_chain(ctx), NULL, 0, timeout);
|
||||
#endif
|
||||
ILibMemory_Free(modules);
|
||||
|
||||
switch (continueResult)
|
||||
{
|
||||
|
||||
@@ -2371,6 +2371,7 @@ ILibExportMethod ILibChain_Continue_Result ILibChain_Continue(void *Chain, ILibC
|
||||
ILibExportMethod ILibChain_Continue_Result ILibChain_Continue(void *Chain, ILibChain_Link **modules, int moduleCount, int maxTimeout)
|
||||
#endif
|
||||
{
|
||||
int useAllModules = (modules == NULL);
|
||||
ILibChain_Continue_Result ret = ILibChain_Continue_Result_EXIT;
|
||||
ILibBaseChain *chain = (ILibBaseChain*)Chain;
|
||||
ILibChain_Link_Hook *nodeHook;
|
||||
@@ -2424,8 +2425,26 @@ ILibExportMethod ILibChain_Continue_Result ILibChain_Continue(void *Chain, ILibC
|
||||
chain->selectTimeout = (int)((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
|
||||
mX = 0;
|
||||
|
||||
if (useAllModules)
|
||||
{
|
||||
if (modules != NULL)
|
||||
{
|
||||
ILibMemory_Free(modules);
|
||||
}
|
||||
modules = ILibChain_GetModules(Chain);
|
||||
moduleCount = (int)(ILibMemory_Size(modules) / sizeof(ILibChain_Link*));
|
||||
}
|
||||
|
||||
while (((modules != NULL && moduleCount > 0 && mX < moduleCount && (module = modules[mX]) != NULL) && (tmpNode.Data = module) != NULL && (chain->node = &tmpNode) != NULL) || (moduleCount == 0 && chain->node != NULL && (module = (ILibChain_Link*)ILibLinkedList_GetDataFromNode(chain->node)) != NULL))
|
||||
{
|
||||
if (useAllModules)
|
||||
{
|
||||
if (ILibLinkedList_GetNode_Search(ILibChain_GetLinks(Chain), NULL, module) == NULL)
|
||||
{
|
||||
++mX;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (module->PreSelectHandler != NULL)
|
||||
{
|
||||
#ifdef MEMORY_CHECK
|
||||
@@ -2550,6 +2569,11 @@ ILibExportMethod ILibChain_Continue_Result ILibChain_Continue(void *Chain, ILibC
|
||||
}
|
||||
}
|
||||
|
||||
if (useAllModules)
|
||||
{
|
||||
if (modules != NULL) { ILibMemory_Free(modules); }
|
||||
}
|
||||
|
||||
ILibRemoteLogging_printf(ILibChainGetLogger(chain), ILibRemoteLogging_Modules_Microstack_Generic, ILibRemoteLogging_Flags_VerbosityLevel_1, "ContinueChain...Ending...");
|
||||
root->node = currentNode;
|
||||
#ifdef WIN32
|
||||
|
||||
@@ -82,6 +82,7 @@ Object.defineProperty(Array.prototype, 'getParameterIndex',
|
||||
|
||||
var promise = require('promise');
|
||||
var localmode = true;
|
||||
var debugmode = false;
|
||||
|
||||
function agentConnect(test, ipcPath)
|
||||
{
|
||||
@@ -107,12 +108,15 @@ function agentConnect(test, ipcPath)
|
||||
});
|
||||
global.client.on('data', function (chunk)
|
||||
{
|
||||
//console.log('DATA: ' + chunk.length, chunk.toString());
|
||||
var len;
|
||||
if (chunk.length < 4) { this.unshift(chunk); return; }
|
||||
if ((len = chunk.readUInt32LE(0)) > chunk.length) { this.unshift(chunk); return; }
|
||||
if ((len = chunk.readUInt32LE(0)) > chunk.length)
|
||||
{
|
||||
if (debugmode) { console.log('RECV: ' + chunk.length + 'bytes but expected ' + len + ' bytes'); }
|
||||
this.unshift(chunk); return;
|
||||
}
|
||||
|
||||
var data = chunk.slice(4, len + 4);
|
||||
var data = chunk.slice(4, len);
|
||||
var payload = null;
|
||||
try
|
||||
{
|
||||
@@ -120,14 +124,22 @@ function agentConnect(test, ipcPath)
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
if (debugmode) { console.log('JSON ERROR on emit: ' + data.toString()); }
|
||||
return;
|
||||
}
|
||||
//console.log('DATA: ' + data.toString());
|
||||
this.test.emit('command', payload);
|
||||
if ((len + 4) < chunk.length)
|
||||
if (debugmode) { console.log('\n' + 'EMIT: ' + data.toString()); }
|
||||
if (payload.cmd == 'server')
|
||||
{
|
||||
console.log('UNSHIFT');
|
||||
this.unshift(chunk.slice(4 + len));
|
||||
this.test.emit('command', payload.value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.test.emit('command', payload);
|
||||
}
|
||||
if (len < chunk.length)
|
||||
{
|
||||
if (debugmode) { console.log('UNSHIFT', len, chunk.length); }
|
||||
this.unshift(chunk.slice(len));
|
||||
}
|
||||
|
||||
});
|
||||
@@ -137,14 +149,20 @@ function agentConnect(test, ipcPath)
|
||||
try
|
||||
{
|
||||
var cmd = "_sendConsoleText = sendConsoleText; sendConsoleText = function(msg,id){ for(i in obj.DAIPC._daipc) { obj.DAIPC._daipc[i]._send({cmd: 'console', value: msg});}};";
|
||||
cmd += "require('MeshAgent')._SendCommand=require('MeshAgent').SendCommand;require('MeshAgent').SendCommand = function(j){ for(i in obj.DAIPC._daipc) { obj.DAIPC._daipc[i]._send({cmd: 'server', value: j});} };"
|
||||
|
||||
//var cmd = "for(i in obj.DAIPC._daipc){ if(obj.DAIPC._daipc[i]._registered==null) { obj.DAIPC._daipc[i]._registered='agentSelfTest'; } }";
|
||||
var reg = { cmd: 'console', value: 'eval "' + cmd + '"' };
|
||||
|
||||
if (debugmode)
|
||||
{
|
||||
console.log(JSON.stringify(reg, null, 1));
|
||||
}
|
||||
var ocmd = Buffer.from(JSON.stringify(reg));
|
||||
var buf = Buffer.alloc(4 + ocmd.length);
|
||||
buf.writeUInt32LE(ocmd.length + 4, 0);
|
||||
ocmd.copy(buf, 4);
|
||||
this.write(buf);
|
||||
|
||||
global.agentipc._res();
|
||||
}
|
||||
catch (f)
|
||||
@@ -157,10 +175,55 @@ function agentConnect(test, ipcPath)
|
||||
function start()
|
||||
{
|
||||
var isservice = false;
|
||||
var nodeid = process.argv.getParameter('nodeID');
|
||||
var ipcPath = process.platform == 'win32' ? ('\\\\.\\pipe\\' + nodeid + '-DAIPC') : (process.cwd() + '/DAIPC');
|
||||
var servicename = process.argv.getParameter('serviceName');
|
||||
var ipcPath = null;
|
||||
var svc = null;
|
||||
debugmode = process.argv.getParameter('debugMode', false);
|
||||
|
||||
if (nodeid != null)
|
||||
try
|
||||
{
|
||||
var svc = require('service-manager').manager.getService(servicename);
|
||||
if(!svc.isRunning())
|
||||
{
|
||||
console.log(' -> Agent: ' + servicename + ' is not running');
|
||||
process._exit();
|
||||
}
|
||||
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.log(' -> Agent: ' + servicename + ' not found');
|
||||
process._exit();
|
||||
}
|
||||
|
||||
if (process.platform == 'win32')
|
||||
{
|
||||
// Find the NodeID from the registry
|
||||
var reg = require('win-registry');
|
||||
try
|
||||
{
|
||||
var val = reg.QueryKey(reg.HKEY.LocalMachine, 'Software\\Open Source\\' + servicename, 'NodeId');
|
||||
val = Buffer.from(val.split('@').join('+').split('$').join('/'), 'base64').toString('hex').toUpperCase();
|
||||
ipcPath = '\\\\.\\pipe\\' + val + '-DAIPC';
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.log(' -> Count not determine NodeID for Agent: ' + servicename);
|
||||
process._exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ipcPath = svc.appWorkingDirectory() + 'DAIPC';
|
||||
}
|
||||
|
||||
if (debugmode)
|
||||
{
|
||||
console.log('\n' + 'ipcPath = ' + ipcPath + '\n');
|
||||
require('ChainViewer').getSnapshot().then(function (c) { console.log(c); });
|
||||
}
|
||||
|
||||
if (ipcPath != null)
|
||||
{
|
||||
localmode = false;
|
||||
console.log(' -> Connecting to agent...');
|
||||
@@ -177,7 +240,6 @@ function start()
|
||||
process._exit();
|
||||
}
|
||||
|
||||
|
||||
this.toAgent = function remote_toAgent(inner)
|
||||
{
|
||||
inner.sessionid = 'pipe';
|
||||
@@ -185,11 +247,15 @@ function start()
|
||||
var ocmd = { cmd: 'console', value: 'eval "require(\'MeshAgent\').emit(\'Command\', JSON.parse(' + icmd + '));"'};
|
||||
ocmd = Buffer.from(JSON.stringify(ocmd));
|
||||
|
||||
if (debugmode) { console.log('\n' + 'To AGENT => ' + JSON.stringify(ocmd) + '\n'); }
|
||||
|
||||
var buf = Buffer.alloc(4 + ocmd.length);
|
||||
buf.writeUInt32LE(ocmd.length + 4, 0);
|
||||
ocmd.copy(buf, 4);
|
||||
global.client.write(buf);
|
||||
};
|
||||
|
||||
if (debugmode=='2') { console.log('\nDEBUG MODE\n'); return; }
|
||||
}
|
||||
|
||||
console.log('Starting Self Test...');
|
||||
@@ -426,7 +492,14 @@ function coreInfo()
|
||||
}
|
||||
}, 5000, ret);
|
||||
|
||||
if (localmode)
|
||||
{
|
||||
require('MeshAgent').emit('Connected', 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret._info = this.consoleCommand("eval \"require('MeshAgent').emit('Connected', 3);\"");
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user