mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
Add signal handlers so we clean up before exiting.
Add SIGTERM and SIGINT signal handlers so that we run the exit handlers before exiting when getting these signals. Fixes an issue where we couldn't run vi after CTRL+C'ing node because the stdin fd was left non-blocking.
This commit is contained in:
22
src/node.cc
22
src/node.cc
@@ -1768,6 +1768,21 @@ static void AtExit() {
|
||||
}
|
||||
|
||||
|
||||
static void SignalExit(int signal) {
|
||||
ev_unloop(EV_DEFAULT_ EVUNLOOP_ALL);
|
||||
}
|
||||
|
||||
|
||||
static int RegisterSignalHandler(int signal, void (*handler)(int)) {
|
||||
struct sigaction sa;
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = handler;
|
||||
sigfillset(&sa.sa_mask);
|
||||
return sigaction(signal, &sa, NULL);
|
||||
}
|
||||
|
||||
|
||||
int Start(int argc, char *argv[]) {
|
||||
// Hack aroung with the argv pointer. Used for process.title = "blah".
|
||||
argv = node::OS::SetupArgs(argc, argv);
|
||||
@@ -1792,10 +1807,9 @@ int Start(int argc, char *argv[]) {
|
||||
V8::SetFlagsFromCommandLine(&v8argc, v8argv, false);
|
||||
|
||||
// Ignore SIGPIPE
|
||||
struct sigaction sa;
|
||||
bzero(&sa, sizeof(sa));
|
||||
sa.sa_handler = SIG_IGN;
|
||||
sigaction(SIGPIPE, &sa, NULL);
|
||||
RegisterSignalHandler(SIGPIPE, SIG_IGN);
|
||||
RegisterSignalHandler(SIGINT, SignalExit);
|
||||
RegisterSignalHandler(SIGTERM, SignalExit);
|
||||
|
||||
|
||||
// Initialize the default ev loop.
|
||||
|
||||
Reference in New Issue
Block a user