logs: use stream.destroy() instead of custom hooks

This commit is contained in:
Girish Ramakrishnan
2024-02-24 17:18:38 +01:00
parent 0e83658aa3
commit 13e62bc738
10 changed files with 19 additions and 10 deletions

View File

@@ -89,7 +89,11 @@ function sudo(tag, args, options, callback) {
e.code = code;
e.signal = signal;
debug(`${tag}: ${SUDO} ${spawnArgs.join(' ').replace(/\n/g, '\\n')} errored`, e);
if (cp.terminated) {
debug(`${tag}: ${SUDO} ${spawnArgs.join(' ').replace(/\n/g, '\\n')} terminated`); // was killed by us
} else {
debug(`${tag}: ${SUDO} ${spawnArgs.join(' ').replace(/\n/g, '\\n')} errored`, e);
}
callback(e);
});
@@ -107,6 +111,7 @@ function sudo(tag, args, options, callback) {
// 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
cp.terminate = function () {
cp.terminated = true; // hint for better debug message in 'exit'
child_process.spawn('kill', ['-SIGTERM', cp.pid], { detached: true }, (error) => { if (error) debug(`${tag} could not terminate`, error); });
};