mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
src: fix kill signal on Windows
Fixes: https://github.com/nodejs/node/issues/42923 PR-URL: https://github.com/nodejs/node/pull/55514 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
This commit is contained in:
parent
2c11d6e61c
commit
eb1cb369fe
@ -1700,8 +1700,8 @@ may not actually terminate the process.
|
||||
See kill(2) for reference.
|
||||
|
||||
On Windows, where POSIX signals do not exist, the `signal` argument will be
|
||||
ignored, and the process will be killed forcefully and abruptly (similar to
|
||||
`'SIGKILL'`).
|
||||
ignored except for `'SIGKILL'`, `'SIGTERM'`, `'SIGINT'` and `'SIGQUIT'`, and the
|
||||
process will always be killed forcefully and abruptly (similar to `'SIGKILL'`).
|
||||
See [Signal Events][] for more details.
|
||||
|
||||
On Linux, child processes of child processes will not be terminated
|
||||
|
@ -314,6 +314,12 @@ class ProcessWrap : public HandleWrap {
|
||||
ProcessWrap* wrap;
|
||||
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This());
|
||||
int signal = args[0]->Int32Value(env->context()).FromJust();
|
||||
#ifdef _WIN32
|
||||
if (signal != SIGKILL && signal != SIGTERM && signal != SIGINT &&
|
||||
signal != SIGQUIT) {
|
||||
signal = SIGKILL;
|
||||
}
|
||||
#endif
|
||||
int err = uv_process_kill(&wrap->process_, signal);
|
||||
args.GetReturnValue().Set(err);
|
||||
}
|
||||
|
@ -39,3 +39,22 @@ assert.strictEqual(cat.signalCode, null);
|
||||
assert.strictEqual(cat.killed, false);
|
||||
cat.kill();
|
||||
assert.strictEqual(cat.killed, true);
|
||||
|
||||
// Test different types of kill signals on Windows.
|
||||
if (common.isWindows) {
|
||||
for (const sendSignal of ['SIGTERM', 'SIGKILL', 'SIGQUIT', 'SIGINT']) {
|
||||
const process = spawn('cmd');
|
||||
process.on('exit', (code, signal) => {
|
||||
assert.strictEqual(code, null);
|
||||
assert.strictEqual(signal, sendSignal);
|
||||
});
|
||||
process.kill(sendSignal);
|
||||
}
|
||||
|
||||
const process = spawn('cmd');
|
||||
process.on('exit', (code, signal) => {
|
||||
assert.strictEqual(code, null);
|
||||
assert.strictEqual(signal, 'SIGKILL');
|
||||
});
|
||||
process.kill('SIGHUP');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user