From 8aac118b69a10a134e57e8e066c56ba7370d25cc Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Thu, 10 Oct 2013 22:28:01 -0700 Subject: [PATCH] process: document kill(0), disallow kill(O_RDWR) The null signal test existed, but only tested the case where the target process existed, not when it did not exist. Also clarified that SIGUSR1 is reserved by Node.js only for receiveing, its not at all reserved when sending a signal with kill(). kill(pid, 'O_RDWR'), or any other node constant, "worked". I fixed this by also checking for 'SIG'. The same as done in the isSignal() function. Now the signal names supported by process.kill() are the same as those supported by process.on(). --- doc/api/process.markdown | 7 +++++-- src/node.js | 3 ++- test/simple/test-process-kill-null.js | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/doc/api/process.markdown b/doc/api/process.markdown index d36af6b..0514f5e 100644 --- a/doc/api/process.markdown +++ b/doc/api/process.markdown @@ -421,6 +421,9 @@ string describing the signal to send. Signal names are strings like 'SIGINT' or 'SIGHUP'. If omitted, the signal will be 'SIGTERM'. See kill(2) for more information. +Will throw an error if target does not exist, and as a special case, a signal of +`0` can be used to test for the existence of a process. + Note that just because the name of this function is `process.kill`, it is really just a signal sender, like the `kill` system call. The signal sent may do something other than kill the target process. @@ -438,8 +441,8 @@ Example of sending a signal to yourself: process.kill(process.pid, 'SIGHUP'); -Note: SIGUSR1 is reserved by node.js. It can be used to kickstart the -debugger. +Note: When SIGUSR1 is received by Node.js it starts the debugger, see +[Signal Events](#process_signal_events). ## process.pid diff --git a/src/node.js b/src/node.js index e5833cb..375bdfa 100644 --- a/src/node.js +++ b/src/node.js @@ -717,7 +717,8 @@ r = process._kill(pid, 0); } else { sig = sig || 'SIGTERM'; - if (startup.lazyConstants()[sig]) { + if (startup.lazyConstants()[sig] && + sig.slice(0, 3) === 'SIG') { r = process._kill(pid, startup.lazyConstants()[sig]); } else { throw new Error('Unknown signal: ' + sig); diff --git a/test/simple/test-process-kill-null.js b/test/simple/test-process-kill-null.js index 708e27d..520210e 100644 --- a/test/simple/test-process-kill-null.js +++ b/test/simple/test-process-kill-null.js @@ -27,7 +27,13 @@ var spawn = require('child_process').spawn; var cat = spawn('cat'); var called; -process.kill(cat.pid, 0); +assert.ok(process.kill(cat.pid, 0)); + +cat.on('exit', function() { + assert.throws(function() { + process.kill(cat.pid, 0); + }, Error); +}); cat.stdout.on('data', function() { called = true; -- 2.7.4