Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
main: Handle SIGINT properly.
Browse files Browse the repository at this point in the history
As explained by http://www.cons.org/cracauer/sigint.html

Signed-off-by: Fedor Indutny <[email protected]>
  • Loading branch information
geirha authored and indutny committed Apr 12, 2014
1 parent 8e823bc commit c61b0e9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2793,9 +2793,9 @@ static void AtExit() {
}


static void SignalExit(int signal) {
static void SignalExit(int signo) {
uv_tty_reset_mode();
_exit(128 + signal);
raise(signo);
}


Expand Down Expand Up @@ -3131,12 +3131,15 @@ static void EnableDebugSignalHandler(int signo) {
}


static void RegisterSignalHandler(int signal, void (*handler)(int signal)) {
static void RegisterSignalHandler(int signal,
void (*handler)(int signal),
bool reset_handler = false) {
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handler;
sa.sa_flags = reset_handler ? SA_RESETHAND : 0;
sigfillset(&sa.sa_mask);
sigaction(signal, &sa, NULL);
CHECK_EQ(sigaction(signal, &sa, NULL), 0);
}


Expand Down Expand Up @@ -3423,8 +3426,8 @@ void Init(int* argc,
}
// Ignore SIGPIPE
RegisterSignalHandler(SIGPIPE, SIG_IGN);
RegisterSignalHandler(SIGINT, SignalExit);
RegisterSignalHandler(SIGTERM, SignalExit);
RegisterSignalHandler(SIGINT, SignalExit, true);
RegisterSignalHandler(SIGTERM, SignalExit, true);
#endif // __POSIX__

V8::SetFatalErrorHandler(node::OnFatalError);
Expand Down

0 comments on commit c61b0e9

Please sign in to comment.