Make child_process.kill always work on windows

This commit is contained in:
Bert Belder 2011-01-17 22:59:25 +01:00
parent bb3bf091d4
commit 6ad629895d
4 changed files with 10 additions and 13 deletions

View File

@ -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

View File

@ -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]);
}
};

View File

@ -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();
}

View File

@ -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();
}