Browse Source

Refine signal handling

pull/350/merge
Max Lv 7 years ago
parent
commit
97c58ad44d
4 changed files with 56 additions and 19 deletions
  1. 3
      src/local.c
  2. 35
      src/redir.c
  3. 2
      src/server.c
  4. 35
      src/tunnel.c

3
src/local.c

@ -1392,7 +1392,7 @@ main(int argc, char **argv)
plugin_host = "127.0.0.1";
plugin_port = tmp_port;
LOGI("plugin %s enabled", plugin);
LOGI("plugin \"%s\" enabled", plugin);
}
if (method == NULL) {
@ -1571,7 +1571,6 @@ main(int argc, char **argv)
}
// Clean up
if (plugin != NULL) {
stop_plugin();
}

35
src/redir.c

@ -748,11 +748,19 @@ accept_cb(EV_P_ ev_io *w, int revents)
ev_io_start(EV_A_ & server->recv_ctx->io);
}
void
signal_cb(int dummy)
static void
signal_cb(EV_P_ ev_signal *w, int revents)
{
keep_resolving = 0;
exit(-1);
if (revents & EV_SIGNAL) {
switch (w->signum) {
case SIGCHLD:
LOGE("plugin service exit unexpectedly");
case SIGINT:
case SIGTERM:
keep_resolving = 0;
ev_unloop(EV_A_ EVUNLOOP_ALL);
}
}
}
int
@ -950,7 +958,7 @@ main(int argc, char **argv)
plugin_host = "127.0.0.1";
plugin_port = tmp_port;
LOGI("plugin %s enabled", plugin);
LOGI("plugin \"%s\" enabled", plugin);
}
if (method == NULL) {
@ -1015,9 +1023,16 @@ main(int argc, char **argv)
// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, SIG_IGN);
signal(SIGINT, signal_cb);
signal(SIGTERM, signal_cb);
signal(SIGCHLD, signal_cb);
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);
ev_signal_start(EV_DEFAULT, &sigint_watcher);
ev_signal_start(EV_DEFAULT, &sigterm_watcher);
ev_signal_start(EV_DEFAULT, &sigchld_watcher);
// Setup keys
LOGI("initializing ciphers... %s", method);
@ -1091,5 +1106,9 @@ main(int argc, char **argv)
stop_plugin();
}
ev_signal_stop(EV_DEFAULT, &sigint_watcher);
ev_signal_stop(EV_DEFAULT, &sigterm_watcher);
ev_signal_stop(EV_DEFAULT, &sigchld_watcher);
return 0;
}

2
src/server.c

@ -1814,7 +1814,7 @@ main(int argc, char **argv)
}
if (plugin != NULL) {
LOGI("plugin %s enabled", plugin);
LOGI("plugin \"%s\" enabled", plugin);
}
if (mode != TCP_ONLY) {

35
src/tunnel.c

@ -710,11 +710,19 @@ accept_cb(EV_P_ ev_io *w, int revents)
ev_timer_start(EV_A_ & remote->send_ctx->watcher);
}
void
signal_cb(int dummy)
static void
signal_cb(EV_P_ ev_signal *w, int revents)
{
keep_resolving = 0;
exit(-1);
if (revents & EV_SIGNAL) {
switch (w->signum) {
case SIGCHLD:
LOGE("plugin service exit unexpectedly");
case SIGINT:
case SIGTERM:
keep_resolving = 0;
ev_unloop(EV_A_ EVUNLOOP_ALL);
}
}
}
int
@ -941,7 +949,7 @@ main(int argc, char **argv)
plugin_host = "127.0.0.1";
plugin_port = tmp_port;
LOGI("plugin %s enabled", plugin);
LOGI("plugin \"%s\" enabled", plugin);
}
if (method == NULL) {
@ -1016,9 +1024,16 @@ main(int argc, char **argv)
// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, SIG_IGN);
signal(SIGINT, signal_cb);
signal(SIGTERM, signal_cb);
signal(SIGCHLD, signal_cb);
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);
ev_signal_start(EV_DEFAULT, &sigint_watcher);
ev_signal_start(EV_DEFAULT, &sigterm_watcher);
ev_signal_start(EV_DEFAULT, &sigchld_watcher);
#endif
// Setup keys
@ -1099,6 +1114,10 @@ main(int argc, char **argv)
stop_plugin();
}
ev_signal_stop(EV_DEFAULT, &sigint_watcher);
ev_signal_stop(EV_DEFAULT, &sigterm_watcher);
ev_signal_stop(EV_DEFAULT, &sigchld_watcher);
#ifdef __MINGW32__
winsock_cleanup();
#endif

Loading…
Cancel
Save