Browse Source

process.kill to use uv_kill

v0.7.4-release
Igor Zinkovsky 13 years ago
parent
commit
24a69d22a0
  1. 15
      src/node.cc
  2. 4
      src/node.h
  3. 48
      src/node.js
  4. 5
      test/simple/test-process-kill-null.js

15
src/node.cc

@ -1623,8 +1623,6 @@ v8::Handle<v8::Value> MemoryUsage(const v8::Arguments& args) {
}
#ifdef __POSIX__
Handle<Value> Kill(const Arguments& args) {
HandleScope scope;
@ -1632,17 +1630,18 @@ Handle<Value> Kill(const Arguments& args) {
return ThrowException(Exception::Error(String::New("Bad argument.")));
}
pid_t pid = args[0]->IntegerValue();
int pid = args[0]->IntegerValue();
int sig = args[1]->Int32Value();
int r = kill(pid, sig);
uv_err_t err = uv_kill(pid, sig);
if (r != 0) return ThrowException(ErrnoException(errno, "kill"));
if (err.code != UV_OK) {
SetErrno(err);
return scope.Close(Integer::New(-1));
}
return Undefined();
}
#endif // __POSIX__
typedef void (UV_DYNAMIC* extInit)(Handle<Object> exports);
@ -2128,9 +2127,9 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
NODE_SET_METHOD(process, "setgid", SetGid);
NODE_SET_METHOD(process, "getgid", GetGid);
#endif // __POSIX__
NODE_SET_METHOD(process, "_kill", Kill);
#endif // __POSIX__
NODE_SET_METHOD(process, "dlopen", DLOpen);

4
src/node.h

@ -54,6 +54,10 @@
#define PATH_MAX MAX_PATH
#endif
#ifdef _WIN32
# define SIGKILL 9
#endif
#include <uv.h>
#include <v8.h>
#include <sys/types.h> /* struct stat */

48
src/node.js

@ -208,6 +208,16 @@
};
};
function errnoException(errorno, syscall) {
// TODO make this more compatible with ErrnoException from src/node.cc
// Once all of Node is using this function the ErrnoException from
// src/node.cc should be removed.
var e = new Error(syscall + ' ' + errorno);
e.errno = e.code = errorno;
e.syscall = syscall;
return e;
}
function createWritableStdioStream(fd) {
var stream;
var tty_wrap = process.binding('tty_wrap');
@ -318,34 +328,30 @@
};
startup.processKillAndExit = function() {
var isWindows = process.platform === 'win32';
process.exit = function(code) {
process.emit('exit', code || 0);
process.reallyExit(code || 0);
};
if (isWindows) {
process.kill = function(pid, sig) {
console.warn('process.kill() is not supported on Windows. Use ' +
'child.kill() to kill a process that was started ' +
'with child_process.spawn().');
}
} else {
process.kill = function(pid, sig) {
// preserve null signal
if (0 === sig) {
process._kill(pid, 0);
process.kill = function(pid, sig) {
var r;
// preserve null signal
if (0 === sig) {
r = process._kill(pid, 0);
} else {
sig = sig || 'SIGTERM';
if (startup.lazyConstants()[sig]) {
r = process._kill(pid, startup.lazyConstants()[sig]);
} else {
sig = sig || 'SIGTERM';
if (startup.lazyConstants()[sig]) {
process._kill(pid, startup.lazyConstants()[sig]);
} else {
throw new Error('Unknown signal: ' + sig);
}
throw new Error('Unknown signal: ' + sig);
}
};
}
}
if (r) {
throw errnoException('kill', errno);
}
};
};
startup.processSignalHandlers = function() {

5
test/simple/test-process-kill-null.js

@ -19,11 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
if (process.platform === 'win32') {
console.warn('Skipping because process.kill is not supported on windows');
process.exit(0);
}
var assert = require('assert');
var spawn = require('child_process').spawn;

Loading…
Cancel
Save