From: Darren Date: Thu, 8 Nov 2012 21:52:06 +0000 (+0000) Subject: Server: Set waiting for server listening before setting UID/GID X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e380bc9ea62c317225b36b86a84b20f75406569b;p=KiwiIRC.git Server: Set waiting for server listening before setting UID/GID --- diff --git a/server/kiwi.js b/server/kiwi.js index 0de98a5..1acb7d0 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -107,8 +107,18 @@ _.each(global.config.servers, function (server) { wl.on('destroy', function (client) { clients.remove(client); }); + + wl.on('listening', webListenerRunning); }); +// Once all the listeners are listening, set the processes UID/GID +var num_listening = 0; +function webListenerRunning() { + num_listening++; + if (num_listening === global.config.servers.length) { + setProcessUid(); + } +} @@ -121,11 +131,13 @@ _.each(global.config.servers, function (server) { process.title = 'kiwiirc'; // Change UID/GID -if ((global.config.group) && (global.config.group !== '')) { - process.setgid(global.config.group); -} -if ((global.config.user) && (global.config.user !== '')) { - process.setuid(global.config.user); +function setProcessUid() { + if ((global.config.group) && (global.config.group !== '')) { + process.setgid(global.config.group); + } + if ((global.config.user) && (global.config.user !== '')) { + process.setuid(global.config.user); + } } diff --git a/server/weblistener.js b/server/weblistener.js index 1c61036..08536fc 100644 --- a/server/weblistener.js +++ b/server/weblistener.js @@ -56,7 +56,9 @@ var WebListener = function (web_config, transports) { // Start socket.io listening on this weblistener this.ws = ws.listen(hs, _.extend({ssl: true}, ws_opts)); - hs.listen(web_config.port, web_config.address); + hs.listen(web_config.port, web_config.address, function () { + that.emit('listening'); + }); console.log('Listening on ' + web_config.address + ':' + web_config.port.toString() + ' with SSL'); } else { @@ -66,7 +68,9 @@ var WebListener = function (web_config, transports) { // Start socket.io listening on this weblistener this.ws = ws.listen(hs, _.extend({ssl: false}, ws_opts)); - hs.listen(web_config.port, web_config.address); + hs.listen(web_config.port, web_config.address, function () { + that.emit('listening'); + }); console.log('Listening on ' + web_config.address + ':' + web_config.port.toString() + ' without SSL'); }