sudo: add kill-child.sh
ultimately, a non-previlieged child cannot kill previlieged parent. all the notes and research in shell.js are not useful.
This commit is contained in:
+6
-6
@@ -9,6 +9,7 @@ const assert = require('assert'),
|
||||
TransformStream = stream.Transform;
|
||||
|
||||
const LOGTAIL_CMD = path.join(__dirname, 'scripts/logtail.sh');
|
||||
const KILL_CHILD_CMD = path.join(__dirname, 'scripts/kill-child.sh');
|
||||
|
||||
class LogStream extends TransformStream {
|
||||
constructor(options) {
|
||||
@@ -68,13 +69,12 @@ function tail(filePaths, options) {
|
||||
if (options.follow) args.push('--follow');
|
||||
|
||||
if (options.sudo) {
|
||||
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);
|
||||
const cp = child_process.spawn('/usr/bin/sudo', [ LOGTAIL_CMD, ...args, ...filePaths ]);
|
||||
cp.terminate = () => {
|
||||
child_process.execFile('/usr/bin/sudo', [ KILL_CHILD_CMD, cp.pid, process.pid ], { encoding: 'utf8' }, (error, stdout, stderr) => {
|
||||
if (error) debug(`tail: failed to kill children`, stdout, stderr);
|
||||
});
|
||||
};
|
||||
cp.stdin.end();
|
||||
return cp;
|
||||
} else {
|
||||
const cp = child_process.spawn('/usr/bin/tail', args.concat(filePaths));
|
||||
@@ -96,7 +96,7 @@ function journalctl(unit, options) {
|
||||
|
||||
if (options.follow) args.push('--follow');
|
||||
|
||||
const cp = spawn('journalctl', args);
|
||||
const cp = child_process.spawn('journalctl', args);
|
||||
cp.terminate = () => cp.kill('SIGKILL');
|
||||
return cp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user