diff --git a/src/logs.js b/src/logs.js index 9b9093c35..c643be6e9 100644 --- a/src/logs.js +++ b/src/logs.js @@ -1,9 +1,9 @@ 'use strict'; const assert = require('assert'), + child_process = require('child_process'), + debug = require('debug')('box:logs'), path = require('path'), - shell = require('./shell.js')('logs'), - spawn = require('child_process').spawn, stream = require('stream'), { StringDecoder } = require('string_decoder'), TransformStream = stream.Transform; @@ -64,14 +64,20 @@ function tail(filePaths, options) { assert.strictEqual(typeof options, 'object'); const lines = options.lines === -1 ? '+1' : options.lines; - const args = options.sudo ? [ LOGTAIL_CMD ] : []; - args.push(`--lines=${lines}`); + const args = [ `--lines=${lines}` ]; if (options.follow) args.push('--follow'); if (options.sudo) { - return shell.sudo(args.concat(filePaths), { quiet: true }, () => {}); + const cp = child_process.spawn('/usr/bin/sudo', [ '-S', LOGTAIL_CMD, ...args, ...filePaths ]); + cp.terminate = () => { // see note in shell.js + child_process.spawn('kill', ['-SIGKILL', -cp.pid], { detached: true }, (error) => { + if (error) debug(`tail could not terminate`, error); + }); + }; + cp.stdin.end(); + return cp; } else { - const cp = spawn('/usr/bin/tail', args.concat(filePaths)); + const cp = child_process.spawn('/usr/bin/tail', args.concat(filePaths)); cp.terminate = () => cp.kill('SIGKILL'); return cp; }