1 #ifndef _WIN32
2 #include <node.h>
3 #include <v8.h>
4 #include <uv.h>
5 #include <assert.h>
6 #include <unistd.h>
7
8 using v8::Boolean;
9 using v8::FunctionCallbackInfo;
10 using v8::Int32;
11 using v8::Value;
12
Handler(int signo,siginfo_t * siginfo,void * ucontext)13 void Handler(int signo, siginfo_t* siginfo, void* ucontext) {
14 char signo_char = signo;
15 int written;
16 do {
17 written = write(1, &signo_char, 1); // write() is signal-safe.
18 } while (written == -1 && errno == EINTR);
19 assert(written == 1);
20 }
21
RegisterSignalHandler(const FunctionCallbackInfo<Value> & args)22 void RegisterSignalHandler(const FunctionCallbackInfo<Value>& args) {
23 assert(args[0]->IsInt32());
24 assert(args[1]->IsBoolean());
25
26 int32_t signo = args[0].As<Int32>()->Value();
27 bool reset_handler = args[1].As<Boolean>()->Value();
28
29 node::RegisterSignalHandler(signo, Handler, reset_handler);
30 }
31
NODE_MODULE_INIT()32 NODE_MODULE_INIT() {
33 NODE_SET_METHOD(exports, "registerSignalHandler", RegisterSignalHandler);
34 }
35
36 #endif // _WIN32
37