From a98bd306f3182bf00f0d261dc1ad04aa2dd98951 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 14 Jun 2018 01:26:32 -0600 Subject: [PATCH] log when using default pipe --- bin/telebitd.js | 11 +++++++---- lib/cli-common.js | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/bin/telebitd.js b/bin/telebitd.js index 92f5c33..60a64b0 100755 --- a/bin/telebitd.js +++ b/bin/telebitd.js @@ -387,16 +387,15 @@ function serveControls() { res.end('{"error":{"message":"unrecognized rpc"}}'); }); - var pipename = common.pipename(state.config); var fs = require('fs'); - if (fs.existsSync(pipename)) { - fs.unlinkSync(pipename); + if (fs.existsSync(state._ipc.path)) { + fs.unlinkSync(state._ipc.path); } // mask is so that processes owned by other users // can speak to this process, which is probably root-owned var oldUmask = process.umask(0x0000); controlServer.listen({ - path: pipename + path: state._ipc.path , writableAll: true , readableAll: true , exclusive: false @@ -443,6 +442,10 @@ function parseConfig(err, text) { } state.config = camelCopy(config); + state._ipc = common.pipename(state.config, true); + if (!state.config.sock) { + console.info('(' + state._ipc.comment + ': ' + state._ipc.path + ')'); + } if (state.config.token && token) { console.warn(); console.warn("Found two tokens:"); diff --git a/lib/cli-common.js b/lib/cli-common.js index 7fa6e76..db90174 100644 --- a/lib/cli-common.js +++ b/lib/cli-common.js @@ -10,14 +10,21 @@ var homedir = os.homedir(); var localshare = '.local/share/telebit'; var localconf = '.config/telebit'; -common.pipename = function (config) { - var pipename = (config.sock || common.DEFAULT_SOCK_NAME); - if (/^win/i.test(os.platform())) { - pipename = '\\\\?\\pipe' + pipename.replace(/\//, '\\'); +common.pipename = function (config, newApi) { + var _ipc = { + path: (config.sock || common.DEFAULT_SOCK_NAME) + , comment: (/^win/i.test(os.platform()) ? 'windows pipe' : 'unix socket') + , type: (/^win/i.test(os.platform()) ? 'pipe' : 'socket') + }; + if ('pipe' === _ipc.type) { + _ipc.path = '\\\\?\\pipe' + pipename.replace(/\//, '\\'); } - return pipename; + if (newApi) { + return _ipc; + } + return _ipc.path; }; -common.DEFAULT_SOCK_NAME = path.join(homedir, localshare, 'var', 'telebit.sock'); +common.DEFAULT_SOCK_NAME = path.join(homedir, localshare, 'var', 'run', 'telebit.sock'); try { mkdirp.sync(path.join(__dirname, '..', 'var', 'log'));