summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAya Morisawa <AyaMorisawa4869@gmail.com>2018-11-20 11:23:32 +0900
committerGitHub <noreply@github.com>2018-11-20 11:23:32 +0900
commit4a77548672a9243e5852753f5d5f9fbb4fb878c7 (patch)
tree2c36a3b507a7cd50b3d02089a29cbecad5836030 /src
parentMerge pull request #3324 from syuilo/l10n_develop (diff)
downloadmisskey-4a77548672a9243e5852753f5d5f9fbb4fb878c7.tar.gz
misskey-4a77548672a9243e5852753f5d5f9fbb4fb878c7.tar.bz2
misskey-4a77548672a9243e5852753f5d5f9fbb4fb878c7.zip
Refactor port checking (#3336)
Diffstat (limited to 'src')
-rw-r--r--src/index.ts14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/index.ts b/src/index.ts
index c58a214054..7ad52ccf2a 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -106,6 +106,14 @@ const runningNodejsVersion = process.version.slice(1).split('.').map(x => parseI
const requiredNodejsVersion = [10, 0, 0];
const satisfyNodejsVersion = !lessThan(runningNodejsVersion, requiredNodejsVersion);
+function isWellKnownPort(port: number): boolean {
+ return port < 1024;
+}
+
+async function isPortAvailable(port: number): Promise<boolean> {
+ return await portscanner.checkPortStatus(port, '127.0.0.1') === 'closed';
+}
+
async function showMachine() {
const logger = new Logger('Machine');
logger.info(`Hostname: ${os.hostname()}`);
@@ -172,12 +180,12 @@ async function init(): Promise<Config> {
process.exit(1);
}
- if (process.platform === 'linux' && !isRoot() && config.port < 1024) {
- Logger.error('You need root privileges to listen on port below 1024 on Linux');
+ if (process.platform === 'linux' && isWellKnownPort(config.port) && !isRoot()) {
+ Logger.error('You need root privileges to listen on well-known port on Linux');
process.exit(1);
}
- if (await portscanner.checkPortStatus(config.port, '127.0.0.1') === 'open') {
+ if (!await isPortAvailable(config.port)) {
Logger.error(`Port ${config.port} is already in use`);
process.exit(1);
}