Satisfy eslint rule linebreak-style

This commit is contained in:
witzig 2017-06-22 18:20:55 +02:00
parent f73eb026b6
commit 44ab04624b
2 changed files with 132 additions and 132 deletions

View file

@ -5,7 +5,7 @@ module.exports = function (grunt) {
// Project configuration. // Project configuration.
grunt.initConfig({ grunt.initConfig({
eslint: { eslint: {
all: ['lib/**/*.js', 'test/**/*.js', 'config/**/*.js', 'Gruntfile.js', 'app.js', 'index.js', 'routes/editorapi.js'] all: ['lib/**/*.js', 'test/**/*.js', 'config/**/*.js', 'services/**/*.js', 'Gruntfile.js', 'app.js', 'index.js', 'routes/editorapi.js']
}, },
nodeunit: { nodeunit: {

View file

@ -1,131 +1,131 @@
'use strict'; 'use strict';
/* Privileged executor. If Mailtrain is started as root, this process keeps the root privilege to be able to spawn workers /* Privileged executor. If Mailtrain is started as root, this process keeps the root privilege to be able to spawn workers
that can chroot. that can chroot.
*/ */
const fileHelpers = require('../lib/file-helpers'); const fileHelpers = require('../lib/file-helpers');
const fork = require('child_process').fork; const fork = require('child_process').fork;
const path = require('path'); const path = require('path');
const log = require('npmlog'); const log = require('npmlog');
const fs = require('fs'); const fs = require('fs');
const privilegeHelpers = require('../lib/privilege-helpers'); const privilegeHelpers = require('../lib/privilege-helpers');
let processes = {}; let processes = {};
function spawnProcess(tid, executable, args, outFile, errFile, cwd, uid, gid) { function spawnProcess(tid, executable, args, outFile, errFile, cwd, uid, gid) {
function reportFail(msg) { function reportFail(msg) {
process.send({ process.send({
type: 'process-failed', type: 'process-failed',
msg, msg,
tid tid
}); });
} }
fs.open(outFile, 'w', (err, outFd) => { fs.open(outFile, 'w', (err, outFd) => {
if (err) { if (err) {
log.error('Executor', err); log.error('Executor', err);
reportFail('Cannot create standard output file.'); reportFail('Cannot create standard output file.');
return; return;
} }
fs.open(errFile, 'w', (err, errFd) => { fs.open(errFile, 'w', (err, errFd) => {
if (err) { if (err) {
log.error('Executor', err); log.error('Executor', err);
reportFail('Cannot create standard error file.'); reportFail('Cannot create standard error file.');
return; return;
} }
privilegeHelpers.ensureMailtrainOwner(outFile, (err) => { privilegeHelpers.ensureMailtrainOwner(outFile, (err) => {
if (err) { if (err) {
log.warn('Executor', 'Cannot change owner of output file of process tid:%s.', tid) log.warn('Executor', 'Cannot change owner of output file of process tid:%s.', tid)
} }
privilegeHelpers.ensureMailtrainOwner(errFile, (err) => { privilegeHelpers.ensureMailtrainOwner(errFile, (err) => {
if (err) { if (err) {
log.warn('Executor', 'Cannot change owner of error output file of process tid:%s.', tid) log.warn('Executor', 'Cannot change owner of error output file of process tid:%s.', tid)
} }
const options = { const options = {
stdio: ['ignore', outFd, errFd, 'ipc'], stdio: ['ignore', outFd, errFd, 'ipc'],
cwd, cwd,
env: {NODE_ENV: process.env.NODE_ENV}, env: {NODE_ENV: process.env.NODE_ENV},
uid, uid,
gid gid
}; };
let child; let child;
try { try {
child = fork(executable, args, options); child = fork(executable, args, options);
} catch (err) { } catch (err) {
log.error('Executor', 'Cannot start process with tid:%s.', tid); log.error('Executor', 'Cannot start process with tid:%s.', tid);
reportFail('Cannot start process.'); reportFail('Cannot start process.');
return; return;
} }
const pid = child.pid; const pid = child.pid;
processes[tid] = child; processes[tid] = child;
log.info('Executor', 'Process started with tid:%s pid:%s.', tid, pid); log.info('Executor', 'Process started with tid:%s pid:%s.', tid, pid);
process.send({ process.send({
type: 'process-started', type: 'process-started',
tid tid
}); });
child.on('close', (code, signal) => { child.on('close', (code, signal) => {
delete processes[tid]; delete processes[tid];
log.info('Executor', 'Process tid:%s pid:%s exited with code %s signal %s.', tid, pid, code, signal); log.info('Executor', 'Process tid:%s pid:%s exited with code %s signal %s.', tid, pid, code, signal);
fs.close(outFd, (err) => { fs.close(outFd, (err) => {
if (err) { if (err) {
log.error('Executor', err); log.error('Executor', err);
} }
fs.close(errFd, (err) => { fs.close(errFd, (err) => {
if (err) { if (err) {
log.error('Executor', err); log.error('Executor', err);
} }
process.send({ process.send({
type: 'process-finished', type: 'process-finished',
tid, tid,
code, code,
signal signal
}); });
}); });
}); });
}); });
}); });
}); });
}); });
}); });
} }
process.on('message', msg => { process.on('message', msg => {
if (msg) { if (msg) {
const type = msg.type; const type = msg.type;
if (type === 'start-report-processor-worker') { if (type === 'start-report-processor-worker') {
const ids = privilegeHelpers.getConfigROUidGid(); const ids = privilegeHelpers.getConfigROUidGid();
spawnProcess(msg.tid, path.join(__dirname, '..', 'workers', 'reports', 'report-processor.js'), [msg.data.id], fileHelpers.getReportContentFile(msg.data), fileHelpers.getReportOutputFile(msg.data), path.join(__dirname, '..', 'workers', 'reports'), ids.uid, ids.gid); spawnProcess(msg.tid, path.join(__dirname, '..', 'workers', 'reports', 'report-processor.js'), [msg.data.id], fileHelpers.getReportContentFile(msg.data), fileHelpers.getReportOutputFile(msg.data), path.join(__dirname, '..', 'workers', 'reports'), ids.uid, ids.gid);
} else if (type === 'stop-process') { } else if (type === 'stop-process') {
const child = processes[msg.tid]; const child = processes[msg.tid];
if (child) { if (child) {
log.info('Executor', 'Killing process tid:%s pid:%s', msg.tid, child.pid); log.info('Executor', 'Killing process tid:%s pid:%s', msg.tid, child.pid);
child.kill(); child.kill();
} else { } else {
log.info('Executor', 'No running process found with tid:%s pid:%s', msg.tid, child.pid); log.info('Executor', 'No running process found with tid:%s pid:%s', msg.tid, child.pid);
} }
} }
} }
}); });
process.send({ process.send({
type: 'executor-started' type: 'executor-started'
}); });