Refine SIGCHLD handling

This commit is contained in:
Max Lv
2017-01-09 17:56:56 +08:00
parent f67518a9d4
commit 94a341fe2c
4 changed files with 37 additions and 39 deletions
+7 -7
View File
@@ -126,6 +126,10 @@ uint64_t rx = 0;
ev_timer stat_update_watcher;
ev_timer block_list_watcher;
static struct ev_signal sigint_watcher;
static struct ev_signal sigterm_watcher;
static struct ev_signal sigchld_watcher;
static struct cork_dllist connections;
static void
@@ -1490,6 +1494,9 @@ signal_cb(EV_P_ ev_signal *w, int revents)
LOGE("plugin service exit unexpectedly");
case SIGINT:
case SIGTERM:
ev_signal_stop(EV_DEFAULT, &sigint_watcher);
ev_signal_stop(EV_DEFAULT, &sigterm_watcher);
ev_signal_stop(EV_DEFAULT, &sigchld_watcher);
ev_unloop(EV_A_ EVUNLOOP_ALL);
}
}
@@ -1833,9 +1840,6 @@ main(int argc, char **argv)
signal(SIGABRT, SIG_IGN);
#endif
struct ev_signal sigint_watcher;
struct ev_signal sigterm_watcher;
struct ev_signal sigchld_watcher;
ev_signal_init(&sigint_watcher, signal_cb, SIGINT);
ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM);
ev_signal_init(&sigchld_watcher, signal_cb, SIGCHLD);
@@ -2003,9 +2007,5 @@ main(int argc, char **argv)
winsock_cleanup();
#endif
ev_signal_stop(EV_DEFAULT, &sigint_watcher);
ev_signal_stop(EV_DEFAULT, &sigterm_watcher);
ev_signal_stop(EV_DEFAULT, &sigchld_watcher);
return 0;
}