Skip to content

Commit

Permalink
[init] First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
AvianFlu committed Jul 8, 2012
0 parents commit 21fc503
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "waitpid",
"sources": [ "src/waitpid.cc" ]
}
]
}
7 changes: 7 additions & 0 deletions lib/waitpid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

var binding = require('../build/Release/waitpid');

module.exports = function waitpid(pid) {
//returns the exit code/signal
return binding.waitpid(pid);
};
41 changes: 41 additions & 0 deletions src/waitpid.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <v8.h>
#include <node.h>
#include <sys/wait.h>
#include <errno.h>

using namespace v8;
using namespace node;

static Handle<Value> Waitpid(const Arguments& args) {
HandleScope scope;
int r, target, *status = NULL;

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

r = waitpid(target, status, NULL);

if (r == -1) {
perror("waitpid");
return ThrowException(Exception::Error(String::New(strerror(errno))));
}

if (WIFEXITED(status)) {
return scope.Close(Integer::New(WEXITSTATUS(status)));
}
else if (WIFSIGNALED(status)) {
return scope.Close(Integer::New(WTERMSIG(status)));
}
return scope.Close(Undefined());
}
else {
return ThrowException(Exception::Error(String::New("Not an integer.")));
}
}


extern "C" void init(Handle<Object> target) {
HandleScope scope;

NODE_SET_METHOD(target, "waitpid", Waitpid);
}

0 comments on commit 21fc503

Please sign in to comment.