Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var client;
var opts;
if (!is.obj(port)) {
opts = makeOptionsObj(port, host);
} else {
opts = port;
}
if (!is.port(opts.port)) {
debug('Error invalid port: '+util.inspect(opts.port));
deferred.reject(new Error('invalid port: '+util.inspect(opts.port)));
return deferred.promise;
}
if (is.nullOrUndefined(opts.host)) {
debug('set host address to default 127.0.0.1');
opts.host = '127.0.0.1';
}
function cleanUp() {
if (client) {
client.removeAllListeners('connect');
client.removeAllListeners('error');
client.end();
client.destroy();
client.unref();
}
//debug('listeners removed from client socket');
}
function onConnectCb() {
exports.runCmd = function(cmd, args, dir, output, cb) {
if (!is.nonEmptyStr(cmd))
return cb(new Error('Bad cmd param: '+inspect(cmd)));
if (is.nullOrUndefined(args))
args = [];
var runInDir = cmd.dir ? cmd.dir : dir;
if (!is.nonEmptyStr(runInDir))
return cb(new Error('Bad dir param: '+inspect(runInDir)));
var errDomain = require('domain').create();
errDomain.on('error', function(err) {
debug('Spawned child process error: '+err.message);
cb(err);
});
var child;
debug('Spawning child process to run '+cmd+', wth args: '+inspect(args));
errDomain.run(function() {
child = spawn(cmd, args, {cwd:runInDir, env:process.env});