Skip to content

Commit

Permalink
Merge pull request chjj#2 from jaredly/master
Browse files Browse the repository at this point in the history
check the sigchld handler
  • Loading branch information
Niall O'Higgins committed Aug 5, 2013
2 parents 38a6b07 + e43d925 commit 4e0de92
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- "0.10"
- "0.8"
34 changes: 22 additions & 12 deletions src/unix/pty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ sigChldHandler(int sig, siginfo_t *sip, void *ctx) {
}
}

void
check_sigchld() {
// retrieve node/libuv's SIGCHLD handler.
struct sigaction node_action;
node_action.sa_flags = 0;
sigaction(SIGCHLD, NULL, &node_action);
if (node_action.sa_sigaction == sigChldHandler) {
return; // it's already installed
}
node_sighandler = node_action.sa_handler;
struct sigaction action;
memset (&action, '\0', sizeof(action));
action.sa_sigaction = sigChldHandler;
action.sa_flags = SA_SIGINFO;
action.sa_flags |= SA_NOCLDSTOP;
// set new SIGCHLD handler. this will call node/libuv's handler at the end.
sigaction(SIGCHLD, &action, NULL);
}

/**
* PtyFork
* pty.fork(file, args, env, cwd, cols, rows)
Expand Down Expand Up @@ -234,6 +253,7 @@ PtyFork(const Arguments& args) {
obj->Set(String::New("pid"), Number::New(pid));
obj->Set(String::New("pty"), String::New(name));
pidMap[pid] = -302;
check_sigchld();

return scope.Close(obj);
}
Expand Down Expand Up @@ -592,25 +612,15 @@ pty_forkpty(int *amaster, char *name,
#endif
}


/**
* Init
*/

extern "C" void
init(Handle<Object> target) {
HandleScope scope;
// retrieve node/libuv's SIGCHLD handler.
struct sigaction node_action;
node_action.sa_flags = 0;
sigaction(SIGCHLD, NULL, &node_action);
node_sighandler = node_action.sa_handler;
struct sigaction action;
memset (&action, '\0', sizeof(action));
action.sa_sigaction = sigChldHandler;
action.sa_flags = SA_SIGINFO;
action.sa_flags |= SA_NOCLDSTOP;
// set new SIGCHLD handler. this will call node/libuv's handler at the end.
sigaction(SIGCHLD, &action, NULL);
check_sigchld();
NODE_SET_METHOD(target, "fork", PtyFork);
NODE_SET_METHOD(target, "open", PtyOpen);
NODE_SET_METHOD(target, "resize", PtyResize);
Expand Down
1 change: 1 addition & 0 deletions test/children/exitCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.exit(5);

0 comments on commit 4e0de92

Please sign in to comment.