diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2011-08-04 20:40:41 +0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2011-08-04 20:40:41 +0400 |
commit | 2bbb46842848b8def1188932755054aa808ccbe6 (patch) | |
tree | 86057becc103d5837bf46ff135c8bb3e6671cf76 /lib | |
parent | ac722bbed6ea846991904ed205a6dc5ece4748c9 (diff) |
child process: bind to libuv's kill process API
Fixes failing test test/simple/test-child-process-kill.js
Diffstat (limited to 'lib')
-rw-r--r-- | lib/child_process_uv.js | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/lib/child_process_uv.js b/lib/child_process_uv.js index 6eed97d08ce..00a43a0790d 100644 --- a/lib/child_process_uv.js +++ b/lib/child_process_uv.js @@ -22,6 +22,7 @@ var EventEmitter = require('events').EventEmitter; var Process = process.binding('process_wrap').Process; var inherits = require('util').inherits; +var constants; // if (!constants) constants = process.binding('constants'); // constructors for lazy loading @@ -215,8 +216,17 @@ function ChildProcess() { this._internal = new Process(); this._internal.onexit = function(exitCode, signalCode) { - if (signalCode) self.signalCode = signalCode; - self.exitCode = exitCode; + // + // follow 0.4.x behaviour: + // + // - normally terminated processes don't touch this.signalCode + // - signaled processes don't touch this.exitCode + // + if (signalCode) { + self.signalCode = signalCode; + } else { + self.exitCode = exitCode; + } if (self.stdin) { self.stdin.destroy(); @@ -298,6 +308,7 @@ ChildProcess.prototype.spawn = function(options) { return r; }; + 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 @@ -310,5 +321,19 @@ function errnoException(errorno, syscall) { ChildProcess.prototype.kill = function(sig) { - throw new Error("implement me"); + if (!constants) { + constants = process.binding('constants'); + } + + sig = sig || 'SIGTERM'; + var signal = constants[sig]; + + if (!signal) { + throw new Error('Unknown signal: ' + sig); + } + + if (!this.signalCode && !this.exitCode) { + var r = this._internal.kill(signal); + // TODO: raise error if r == -1? + } }; |