make sudo commands terminate properly

sudo forks and execs the program. sudo also hangs around as the parent of the program waiting on the program and also forwarding signals.
sudo does not forward signals when the originator comes from the same process group. recently, there has been a change where it will
forward signals as long as sudo or the command is not the group leader (https://www.sudo.ws/repos/sudo/rev/d1bf60eac57f)
for us, this means that calling kill from this node process doesn't work since it's in the same group (and ubuntu 22 doesn't have the above fix).
the workaround is to invoke a kill from a different process group and this is done by starting detached
another idea is: use "ps --pid cp.pid -o pid=" to get the pid of the command and then send it signal directly

see also: https://dxuuu.xyz/sudo.html
This commit is contained in:
Girish Ramakrishnan
2024-02-24 15:26:48 +01:00
parent 8e4506382d
commit 0e83658aa3
5 changed files with 15 additions and 4 deletions

View File

@@ -2050,7 +2050,7 @@ async function getLogs(app, options) {
const cp = logs.tail(logPaths, { lines: options.lines, follow: options.follow });
const logStream = new logs.LogStream({ format: options.format || 'json', source: appId });
logStream.close = cp.kill.bind(cp, 'SIGTERM'); // hook for caller. closing stream kills the child process
logStream.close = cp.terminate; // closing stream kills the child process
cp.stdout.pipe(logStream);