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

Commit c61b0e9

Browse files
geirhaindutny
authored andcommitted
main: Handle SIGINT properly.
As explained by http://www.cons.org/cracauer/sigint.html Signed-off-by: Fedor Indutny <[email protected]>
1 parent 8e823bc commit c61b0e9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/node.cc

+9-6
Original file line numberDiff line numberDiff line change
@@ -2793,9 +2793,9 @@ static void AtExit() {
27932793
}
27942794

27952795

2796-
static void SignalExit(int signal) {
2796+
static void SignalExit(int signo) {
27972797
uv_tty_reset_mode();
2798-
_exit(128 + signal);
2798+
raise(signo);
27992799
}
28002800

28012801

@@ -3131,12 +3131,15 @@ static void EnableDebugSignalHandler(int signo) {
31313131
}
31323132

31333133

3134-
static void RegisterSignalHandler(int signal, void (*handler)(int signal)) {
3134+
static void RegisterSignalHandler(int signal,
3135+
void (*handler)(int signal),
3136+
bool reset_handler = false) {
31353137
struct sigaction sa;
31363138
memset(&sa, 0, sizeof(sa));
31373139
sa.sa_handler = handler;
3140+
sa.sa_flags = reset_handler ? SA_RESETHAND : 0;
31383141
sigfillset(&sa.sa_mask);
3139-
sigaction(signal, &sa, NULL);
3142+
CHECK_EQ(sigaction(signal, &sa, NULL), 0);
31403143
}
31413144

31423145

@@ -3423,8 +3426,8 @@ void Init(int* argc,
34233426
}
34243427
// Ignore SIGPIPE
34253428
RegisterSignalHandler(SIGPIPE, SIG_IGN);
3426-
RegisterSignalHandler(SIGINT, SignalExit);
3427-
RegisterSignalHandler(SIGTERM, SignalExit);
3429+
RegisterSignalHandler(SIGINT, SignalExit, true);
3430+
RegisterSignalHandler(SIGTERM, SignalExit, true);
34283431
#endif // __POSIX__
34293432

34303433
V8::SetFatalErrorHandler(node::OnFatalError);

0 commit comments

Comments
 (0)