Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/waitpid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using namespace v8;
using namespace node;

#if NODE_MINOR_VERSION==10
static Handle<Value> Waitpid(const Arguments& args) {
HandleScope scope;
int r, child, status;
Expand Down Expand Up @@ -43,6 +44,43 @@ extern "C" void init(Handle<Object> target) {
HandleScope scope;
NODE_SET_METHOD(target, "waitpid", Waitpid);
}
#endif

#if NODE_MINOR_VERSION>10
void Waitpid(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);

int r, child, status;

if (args[0]->IsInt32()) {
child = args[0]->Int32Value();

do {
r = waitpid(child, &status, 0);
} while (r != -1);

Local<Object> result = Object::New(isolate);

if (WIFEXITED(status)) {
result->Set(String::NewFromUtf8(isolate, "exitCode"), Integer::New(isolate, WEXITSTATUS(status)));
result->Set(String::NewFromUtf8(isolate, "signalCode"), Null(isolate));
return;
}
else if (WIFSIGNALED(status)) {
result->Set(String::NewFromUtf8(isolate, "exitCode"), Null(isolate));
result->Set(String::NewFromUtf8(isolate, "signalCode"), Integer::New(isolate, WTERMSIG(status)));
return;
}
}
else {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Not an integer.")));
}
}

extern "C" void init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "waitpid", Waitpid);
}
#endif

NODE_MODULE(waitpid, init)