Make child_process.kill always work on windows
This commit is contained in:
parent
bb3bf091d4
commit
6ad629895d
@ -23,9 +23,6 @@
|
|||||||
block; on windows a libeio thread is used to call CreateProcess.
|
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
|
So this can't really be fixed, but it could be worked around by adding a
|
||||||
'spawn' or 'pid' event.
|
'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
|
* passing socket custom_fds is not supported
|
||||||
* child_process.exec() only works on systems with msys installed.
|
* child_process.exec() only works on systems with msys installed.
|
||||||
It's because it relies on the 'sh' shell. The default windows shell
|
It's because it relies on the 'sh' shell. The default windows shell
|
||||||
|
@ -172,12 +172,11 @@ util.inherits(ChildProcess, EventEmitter);
|
|||||||
|
|
||||||
|
|
||||||
ChildProcess.prototype.kill = function(sig) {
|
ChildProcess.prototype.kill = function(sig) {
|
||||||
if (this._internal.pid) {
|
if (!this.killed && !this.exited) {
|
||||||
this.killed = true;
|
|
||||||
if (!constants) constants = process.binding('constants');
|
if (!constants) constants = process.binding('constants');
|
||||||
sig = sig || 'SIGTERM';
|
sig = sig || 'SIGTERM';
|
||||||
if (!constants[sig]) throw new Error('Unknown signal: ' + sig);
|
if (!constants[sig]) throw new Error('Unknown signal: ' + sig);
|
||||||
return this._internal.kill(constants[sig]);
|
this.killed = this._internal.kill(constants[sig]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -240,7 +240,8 @@ Handle<Value> ChildProcess::Kill(const Arguments& args) {
|
|||||||
assert(child);
|
assert(child);
|
||||||
|
|
||||||
if (child->pid_ < 1) {
|
if (child->pid_ < 1) {
|
||||||
return ThrowException(Exception::Error(String::New("No such process")));
|
// nothing to do
|
||||||
|
return False();
|
||||||
}
|
}
|
||||||
|
|
||||||
int sig = SIGTERM;
|
int sig = SIGTERM;
|
||||||
@ -249,15 +250,15 @@ Handle<Value> ChildProcess::Kill(const Arguments& args) {
|
|||||||
if (args[0]->IsNumber()) {
|
if (args[0]->IsNumber()) {
|
||||||
sig = args[0]->Int32Value();
|
sig = args[0]->Int32Value();
|
||||||
} else {
|
} else {
|
||||||
return ThrowException(Exception::Error(String::New("Bad argument.")));
|
return ThrowException(Exception::TypeError(String::New("Bad argument.")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child->Kill(sig) != 0) {
|
if (child->Kill(sig) != 0) {
|
||||||
return ThrowException(Exception::Error(String::New(strerror(errno))));
|
return ThrowException(ErrnoException(errno, "Kill"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Undefined();
|
return True();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -810,15 +810,15 @@ Handle<Value> ChildProcess::Kill(const Arguments& args) {
|
|||||||
if (args[0]->IsNumber()) {
|
if (args[0]->IsNumber()) {
|
||||||
sig = args[0]->Int32Value();
|
sig = args[0]->Int32Value();
|
||||||
} else {
|
} else {
|
||||||
return ThrowException(Exception::Error(String::New("Bad argument.")));
|
return ThrowException(Exception::TypeError(String::New("Bad argument.")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_kill(child, sig) != 0) {
|
if (do_kill(child, sig) != 0) {
|
||||||
return ThrowException(Exception::Error(String::New(strerror(errno))));
|
return ThrowException(ErrnoException(GetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Undefined();
|
return True();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user