forked from AvianFlu/node-waitpid
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 21fc503
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "waitpid", | ||
"sources": [ "src/waitpid.cc" ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |