From 8f7ab08a996139fa8d40a9bca048b953104f5b8f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 3 Jul 2018 04:37:41 -0600 Subject: [PATCH] don't define host and port, even as null --- bin/telebitd.js | 20 ++++++++++++-------- tests/windows-pipe.js | 20 ++++++++++++++++++++ tests/windows-spawn-pipe.js | 22 ++++++++++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 tests/windows-pipe.js create mode 100644 tests/windows-spawn-pipe.js diff --git a/bin/telebitd.js b/bin/telebitd.js index 03dfd7e..7683c30 100755 --- a/bin/telebitd.js +++ b/bin/telebitd.js @@ -571,17 +571,21 @@ function serveControlsHelper() { // mask is so that processes owned by other users // can speak to this process, which is probably root-owned var oldUmask = process.umask(0x0000); + var serverOpts = { + writableAll: true + , readableAll: true + , exclusive: false + }; if ('socket' === state._ipc.type) { require('mkdirp').sync(path.dirname(state._ipc.path)); } - controlServer.listen({ - path: state._ipc.path || null - , host: 'localhost' - , port: state._ipc.port || null - , writableAll: true - , readableAll: true - , exclusive: false - }, function () { + if (state._ipc.port) { + serverOpts.host = 'localhost'; + serverOpts.port = state._ipc.port; + } else { + serverOpts.path = state._ipc.path; + } + controlServer.listen(serverOpts, function () { process.umask(oldUmask); var address = this.address(); if (address.port) { diff --git a/tests/windows-pipe.js b/tests/windows-pipe.js new file mode 100644 index 0000000..7beb384 --- /dev/null +++ b/tests/windows-pipe.js @@ -0,0 +1,20 @@ +'use strict'; + +var os = require('os'); +var net = require('net'); +var ipc = { + path: /^win/.test(os.platform()) ? '\\\\.\\pipe\\X:/name/of/pipe' : (__dirname + '/tmp.sock') +}; +var oldUmask = process.umask(0x0000); +var server = net.createServer(); + +server.listen({ + path: ipc.path || null +, host: 'localhost' +, port: ipc.port || null +, writeableAll: true +, readableAll: true +}, function () { + process.umask(oldUmask); + console.log("Listening on", this.address()); +}); diff --git a/tests/windows-spawn-pipe.js b/tests/windows-spawn-pipe.js new file mode 100644 index 0000000..a4f1b39 --- /dev/null +++ b/tests/windows-spawn-pipe.js @@ -0,0 +1,22 @@ +'use strict'; + +var path = require('path'); +var spawn = require('child_process').spawn; +var args = [ + path.join(__dirname, 'windows-pipe.js') +]; +var subprocess = spawn( + 'node' +, args +, { detached: true + , stdio: [ 'ignore', process.stdout, process.stderr ] + } +); +//console.log('[debug]', vars.telebitNode, args.join(' ')); +subprocess.unref(); +subprocess.on('error', function (_err) { + console.error(_err); +}); +subprocess.on('exit', function (code, signal) { + console.error('' + code + ' ' + signal + ' failure to launch'); +});