From fc6d1c462f551db8f94b40e4245e32b37ad49487 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Fri, 25 Aug 2017 23:03:37 +0300 Subject: [PATCH 1/2] exec to execFile switch --- routes/shepherd.js | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/routes/shepherd.js b/routes/shepherd.js index 6cd9104..a2a6ec1 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -21,7 +21,8 @@ const electron = require('electron'), AdmZip = require('adm-zip'), remoteFileSize = require('remote-file-size'), Promise = require('bluebird'), - {shell} = require('electron'); + {shell} = require('electron'), + { execFile } = require('child_process'); const fixPath = require('fix-path'); var ps = require('ps-node'), @@ -906,8 +907,12 @@ shepherd.quitKomodod = function(timeout = 100) { coindExitInterval[key] = setInterval(function() { shepherd.killRogueProcess('komodo-cli'); - console.log('exec ' + komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop'); - exec(komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop', function(error, stdout, stderr) { + let _arg = []; + if (chain) { + _arg.push(`-ac_name=${chain}`); + } + _arg.push('stop'); + execFile(`${komodocliBin}`, _arg, function(error, stdout, stderr) { console.log(`stdout: ${stdout}`); console.log(`stderr: ${stderr}`); @@ -1026,7 +1031,9 @@ shepherd.post('/cli', function(req, res, next) { }); } else { shepherd.killRogueProcess('komodo-cli'); - exec(komodocliBin + (_chain ? ' -ac_name=' + _chain : '') + ' ' + _cmd + _params, function(error, stdout, stderr) { + let _arg = (_chain ? ' -ac_name=' + _chain : '') + ' ' + _cmd + _params; + _arg = _arg.trim().split(' '); + execFile(komodocliBin, _arg, function(error, stdout, stderr) { console.log(`stdout: ${stdout}`); console.log(`stderr: ${stderr}`); @@ -2132,7 +2139,9 @@ function herder(flock, data) { console.log(`daemon param ${data.ac_custom_param}`); coindInstanceRegistry[data.ac_name] = true; - exec(`${komododBin} ${coindACParam}${data.ac_options.join(' ')}${_customParam}`, { + let _arg = `${coindACParam}${data.ac_options.join(' ')}${_customParam}`; + _arg = _arg.trim().split(' '); + execFile(`${komododBin}`, _arg, { maxBuffer: 1024 * 10000 // 10 mb }, function(error, stdout, stderr) { shepherd.writeLog(`stdout: ${stdout}`); @@ -2549,16 +2558,16 @@ function formatBytes(bytes, decimals) { const k = 1000; const dm = (decimals + 1) || 3; const sizes = [ - 'Bytes', - 'KB', - 'MB', - 'GB', - 'TB', - 'PB', - 'EB', - 'ZB', - 'YB' - ]; + 'Bytes', + 'KB', + 'MB', + 'GB', + 'TB', + 'PB', + 'EB', + 'ZB', + 'YB' + ]; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; From cfaa2d337aeea7cc85254a4e938557c670fad936 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sat, 26 Aug 2017 03:59:17 -0700 Subject: [PATCH 2/2] cli passphru fix --- routes/shepherd.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/routes/shepherd.js b/routes/shepherd.js index a2a6ec1..1bbed1f 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -906,7 +906,6 @@ shepherd.quitKomodod = function(timeout = 100) { const chain = key !== 'komodod' ? key : null; coindExitInterval[key] = setInterval(function() { - shepherd.killRogueProcess('komodo-cli'); let _arg = []; if (chain) { _arg.push(`-ac_name=${chain}`); @@ -918,6 +917,7 @@ shepherd.quitKomodod = function(timeout = 100) { if (stdout.indexOf('EOF reached') > -1 || stderr.indexOf('EOF reached') > -1 || + (error && error.toString().indexOf('Command failed') > -1 && !stderr) || // win "special snowflake" case stdout.indexOf('connect to server: unknown (code -1)') > -1 || stderr.indexOf('connect to server: unknown (code -1)') > -1) { delete coindInstanceRegistry[key]; @@ -927,6 +927,7 @@ shepherd.quitKomodod = function(timeout = 100) { if (error !== null) { console.log(`exec error: ${error}`); } + shepherd.killRogueProcess('komodo-cli'); }); }, timeout); } @@ -1030,7 +1031,6 @@ shepherd.post('/cli', function(req, res, next) { } }); } else { - shepherd.killRogueProcess('komodo-cli'); let _arg = (_chain ? ' -ac_name=' + _chain : '') + ' ' + _cmd + _params; _arg = _arg.trim().split(' '); execFile(komodocliBin, _arg, function(error, stdout, stderr) { @@ -1056,6 +1056,7 @@ shepherd.post('/cli', function(req, res, next) { } res.end(JSON.stringify(responseObj)); + shepherd.killRogueProcess('komodo-cli'); }); } }