mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-20 02:03:15 +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)
|
if (duk_peval_string(agent->meshCoreCtx, "require('agent-selftest')();") != 0)
|
||||||
{
|
{
|
||||||
printf(" -> Loading Test Script.................[FAILED]\n");
|
printf(" -> Loading Test Script.................[FAILED]\n");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
duk_pop(agent->meshCoreCtx);
|
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"))
|
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
|
#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
|
#else
|
||||||
continueResult = ILibChain_Continue(duk_ctx_chain(ctx), modules, count, timeout);
|
continueResult = ILibChain_Continue(duk_ctx_chain(ctx), NULL, 0, timeout);
|
||||||
#endif
|
#endif
|
||||||
ILibMemory_Free(modules);
|
|
||||||
|
|
||||||
switch (continueResult)
|
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)
|
ILibExportMethod ILibChain_Continue_Result ILibChain_Continue(void *Chain, ILibChain_Link **modules, int moduleCount, int maxTimeout)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
int useAllModules = (modules == NULL);
|
||||||
ILibChain_Continue_Result ret = ILibChain_Continue_Result_EXIT;
|
ILibChain_Continue_Result ret = ILibChain_Continue_Result_EXIT;
|
||||||
ILibBaseChain *chain = (ILibBaseChain*)Chain;
|
ILibBaseChain *chain = (ILibBaseChain*)Chain;
|
||||||
ILibChain_Link_Hook *nodeHook;
|
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));
|
chain->selectTimeout = (int)((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
|
||||||
mX = 0;
|
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))
|
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)
|
if (module->PreSelectHandler != NULL)
|
||||||
{
|
{
|
||||||
#ifdef MEMORY_CHECK
|
#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...");
|
ILibRemoteLogging_printf(ILibChainGetLogger(chain), ILibRemoteLogging_Modules_Microstack_Generic, ILibRemoteLogging_Flags_VerbosityLevel_1, "ContinueChain...Ending...");
|
||||||
root->node = currentNode;
|
root->node = currentNode;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ Object.defineProperty(Array.prototype, 'getParameterIndex',
|
|||||||
|
|
||||||
var promise = require('promise');
|
var promise = require('promise');
|
||||||
var localmode = true;
|
var localmode = true;
|
||||||
|
var debugmode = false;
|
||||||
|
|
||||||
function agentConnect(test, ipcPath)
|
function agentConnect(test, ipcPath)
|
||||||
{
|
{
|
||||||
@@ -107,12 +108,15 @@ function agentConnect(test, ipcPath)
|
|||||||
});
|
});
|
||||||
global.client.on('data', function (chunk)
|
global.client.on('data', function (chunk)
|
||||||
{
|
{
|
||||||
//console.log('DATA: ' + chunk.length, chunk.toString());
|
|
||||||
var len;
|
var len;
|
||||||
if (chunk.length < 4) { this.unshift(chunk); return; }
|
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;
|
var payload = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -120,14 +124,22 @@ function agentConnect(test, ipcPath)
|
|||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
|
if (debugmode) { console.log('JSON ERROR on emit: ' + data.toString()); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//console.log('DATA: ' + data.toString());
|
if (debugmode) { console.log('\n' + 'EMIT: ' + data.toString()); }
|
||||||
this.test.emit('command', payload);
|
if (payload.cmd == 'server')
|
||||||
if ((len + 4) < chunk.length)
|
|
||||||
{
|
{
|
||||||
console.log('UNSHIFT');
|
this.test.emit('command', payload.value);
|
||||||
this.unshift(chunk.slice(4 + len));
|
}
|
||||||
|
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
|
try
|
||||||
{
|
{
|
||||||
var cmd = "_sendConsoleText = sendConsoleText; sendConsoleText = function(msg,id){ for(i in obj.DAIPC._daipc) { obj.DAIPC._daipc[i]._send({cmd: 'console', value: msg});}};";
|
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 + '"' };
|
var reg = { cmd: 'console', value: 'eval "' + cmd + '"' };
|
||||||
|
|
||||||
|
if (debugmode)
|
||||||
|
{
|
||||||
|
console.log(JSON.stringify(reg, null, 1));
|
||||||
|
}
|
||||||
var ocmd = Buffer.from(JSON.stringify(reg));
|
var ocmd = Buffer.from(JSON.stringify(reg));
|
||||||
var buf = Buffer.alloc(4 + ocmd.length);
|
var buf = Buffer.alloc(4 + ocmd.length);
|
||||||
buf.writeUInt32LE(ocmd.length + 4, 0);
|
buf.writeUInt32LE(ocmd.length + 4, 0);
|
||||||
ocmd.copy(buf, 4);
|
ocmd.copy(buf, 4);
|
||||||
this.write(buf);
|
this.write(buf);
|
||||||
|
|
||||||
global.agentipc._res();
|
global.agentipc._res();
|
||||||
}
|
}
|
||||||
catch (f)
|
catch (f)
|
||||||
@@ -157,10 +175,55 @@ function agentConnect(test, ipcPath)
|
|||||||
function start()
|
function start()
|
||||||
{
|
{
|
||||||
var isservice = false;
|
var isservice = false;
|
||||||
var nodeid = process.argv.getParameter('nodeID');
|
var servicename = process.argv.getParameter('serviceName');
|
||||||
var ipcPath = process.platform == 'win32' ? ('\\\\.\\pipe\\' + nodeid + '-DAIPC') : (process.cwd() + '/DAIPC');
|
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;
|
localmode = false;
|
||||||
console.log(' -> Connecting to agent...');
|
console.log(' -> Connecting to agent...');
|
||||||
@@ -177,7 +240,6 @@ function start()
|
|||||||
process._exit();
|
process._exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.toAgent = function remote_toAgent(inner)
|
this.toAgent = function remote_toAgent(inner)
|
||||||
{
|
{
|
||||||
inner.sessionid = 'pipe';
|
inner.sessionid = 'pipe';
|
||||||
@@ -185,11 +247,15 @@ function start()
|
|||||||
var ocmd = { cmd: 'console', value: 'eval "require(\'MeshAgent\').emit(\'Command\', JSON.parse(' + icmd + '));"'};
|
var ocmd = { cmd: 'console', value: 'eval "require(\'MeshAgent\').emit(\'Command\', JSON.parse(' + icmd + '));"'};
|
||||||
ocmd = Buffer.from(JSON.stringify(ocmd));
|
ocmd = Buffer.from(JSON.stringify(ocmd));
|
||||||
|
|
||||||
|
if (debugmode) { console.log('\n' + 'To AGENT => ' + JSON.stringify(ocmd) + '\n'); }
|
||||||
|
|
||||||
var buf = Buffer.alloc(4 + ocmd.length);
|
var buf = Buffer.alloc(4 + ocmd.length);
|
||||||
buf.writeUInt32LE(ocmd.length + 4, 0);
|
buf.writeUInt32LE(ocmd.length + 4, 0);
|
||||||
ocmd.copy(buf, 4);
|
ocmd.copy(buf, 4);
|
||||||
global.client.write(buf);
|
global.client.write(buf);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (debugmode=='2') { console.log('\nDEBUG MODE\n'); return; }
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Starting Self Test...');
|
console.log('Starting Self Test...');
|
||||||
@@ -426,7 +492,14 @@ function coreInfo()
|
|||||||
}
|
}
|
||||||
}, 5000, ret);
|
}, 5000, ret);
|
||||||
|
|
||||||
|
if (localmode)
|
||||||
|
{
|
||||||
require('MeshAgent').emit('Connected', 3);
|
require('MeshAgent').emit('Connected', 3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret._info = this.consoleCommand("eval \"require('MeshAgent').emit('Connected', 3);\"");
|
||||||
|
}
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user