mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
lib: allow process kill by signal number
This brings the behaviour in line with the documentation. PR-URL: https://github.com/nodejs/node/pull/16944 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
c9b42c4c13
commit
7ca4ca8cc3
@ -162,8 +162,8 @@ function setupKillAndExit() {
|
||||
}
|
||||
|
||||
// preserve null signal
|
||||
if (0 === sig) {
|
||||
err = process._kill(pid, 0);
|
||||
if (sig === (sig | 0)) {
|
||||
err = process._kill(pid, sig);
|
||||
} else {
|
||||
sig = sig || 'SIGTERM';
|
||||
if (constants[sig]) {
|
||||
|
@ -57,16 +57,19 @@ assert.throws(function() { process.kill(1 / 0); },
|
||||
assert.throws(function() { process.kill(-1 / 0); },
|
||||
invalidPidArgument);
|
||||
|
||||
// Test that kill throws an error for invalid signal
|
||||
const unknownSignal = common.expectsError({
|
||||
// Test that kill throws an error for unknown signal names
|
||||
common.expectsError(() => process.kill(0, 'test'), {
|
||||
code: 'ERR_UNKNOWN_SIGNAL',
|
||||
type: TypeError,
|
||||
message: 'Unknown signal: test'
|
||||
});
|
||||
|
||||
|
||||
assert.throws(function() { process.kill(1, 'test'); },
|
||||
unknownSignal);
|
||||
// Test that kill throws an error for invalid signal numbers
|
||||
common.expectsError(() => process.kill(0, 987), {
|
||||
code: 'EINVAL',
|
||||
type: Error,
|
||||
message: 'kill EINVAL'
|
||||
});
|
||||
|
||||
// Test kill argument processing in valid cases.
|
||||
//
|
||||
@ -99,6 +102,11 @@ kill(0, undefined, 0, 15);
|
||||
kill('0', 'SIGHUP', 0, 1);
|
||||
kill('0', undefined, 0, 15);
|
||||
|
||||
// Confirm that numeric signal arguments are supported
|
||||
|
||||
kill(0, 1, 0, 1);
|
||||
kill(0, 15, 0, 15);
|
||||
|
||||
// negative numbers are meaningful on unix
|
||||
kill(-1, 'SIGHUP', -1, 1);
|
||||
kill(-1, undefined, -1, 15);
|
||||
|
Loading…
Reference in New Issue
Block a user