Browse Source

Make child_process.kill always work on windows

v0.7.4-release
Bert Belder 14 years ago
parent
commit
6ad629895d
  1. 3
      TODO.win32
  2. 5
      lib/child_process.js
  3. 9
      src/node_child_process.cc
  4. 6
      src/node_child_process_win32.cc

3
TODO.win32

@ -23,9 +23,6 @@
block; on windows a libeio thread is used to call CreateProcess.
So this can't really be fixed, but it could be worked around by adding a
'spawn' or 'pid' event.
* kill() doesn't work when the pid is not available yet. All the plumbing
is there to make it work, but lib/child_process.js just doesn't call
ChildProcess::Kill() as long as the pid is not known.
* passing socket custom_fds is not supported
* child_process.exec() only works on systems with msys installed.
It's because it relies on the 'sh' shell. The default windows shell

5
lib/child_process.js

@ -172,12 +172,11 @@ util.inherits(ChildProcess, EventEmitter);
ChildProcess.prototype.kill = function(sig) {
if (this._internal.pid) {
this.killed = true;
if (!this.killed && !this.exited) {
if (!constants) constants = process.binding('constants');
sig = sig || 'SIGTERM';
if (!constants[sig]) throw new Error('Unknown signal: ' + sig);
return this._internal.kill(constants[sig]);
this.killed = this._internal.kill(constants[sig]);
}
};

9
src/node_child_process.cc

@ -240,7 +240,8 @@ Handle<Value> ChildProcess::Kill(const Arguments& args) {
assert(child);
if (child->pid_ < 1) {
return ThrowException(Exception::Error(String::New("No such process")));
// nothing to do
return False();
}
int sig = SIGTERM;
@ -249,15 +250,15 @@ Handle<Value> ChildProcess::Kill(const Arguments& args) {
if (args[0]->IsNumber()) {
sig = args[0]->Int32Value();
} else {
return ThrowException(Exception::Error(String::New("Bad argument.")));
return ThrowException(Exception::TypeError(String::New("Bad argument.")));
}
}
if (child->Kill(sig) != 0) {
return ThrowException(Exception::Error(String::New(strerror(errno))));
return ThrowException(ErrnoException(errno, "Kill"));
}
return Undefined();
return True();
}

6
src/node_child_process_win32.cc

@ -810,15 +810,15 @@ Handle<Value> ChildProcess::Kill(const Arguments& args) {
if (args[0]->IsNumber()) {
sig = args[0]->Int32Value();
} else {
return ThrowException(Exception::Error(String::New("Bad argument.")));
return ThrowException(Exception::TypeError(String::New("Bad argument.")));
}
}
if (do_kill(child, sig) != 0) {
return ThrowException(Exception::Error(String::New(strerror(errno))));
return ThrowException(ErrnoException(GetLastError()));
}
return Undefined();
return True();
}

Loading…
Cancel
Save