mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-29 20:43:44 +00:00
Refine SIGCHLD handling
This commit is contained in:
+14
-18
@@ -108,6 +108,13 @@ static int mode = TCP_ONLY;
|
||||
static int ipv6first = 0;
|
||||
static int fast_open = 0;
|
||||
|
||||
static struct ev_signal sigint_watcher;
|
||||
static struct ev_signal sigterm_watcher;
|
||||
static struct ev_signal sigchld_watcher;
|
||||
#ifndef __MINGW32__
|
||||
struct ev_signal sigusr1_watcher;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SETRLIMIT
|
||||
#ifndef LIB_ONLY
|
||||
static int nofile = 0;
|
||||
@@ -1118,12 +1125,6 @@ create_remote(listen_ctx_t *listener,
|
||||
return remote;
|
||||
}
|
||||
|
||||
void
|
||||
resolve_int_cb(int dummy)
|
||||
{
|
||||
keep_resolving = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
signal_cb(EV_P_ ev_signal *w, int revents)
|
||||
{
|
||||
@@ -1136,8 +1137,14 @@ signal_cb(EV_P_ ev_signal *w, int revents)
|
||||
#ifndef __MINGW32__
|
||||
case SIGUSR1:
|
||||
#endif
|
||||
ev_signal_stop(EV_DEFAULT, &sigint_watcher);
|
||||
ev_signal_stop(EV_DEFAULT, &sigterm_watcher);
|
||||
ev_signal_stop(EV_DEFAULT, &sigchld_watcher);
|
||||
#ifndef __MINGW32__
|
||||
ev_signal_stop(EV_DEFAULT, &sigusr1_watcher);
|
||||
#endif
|
||||
keep_resolving = 0;
|
||||
ev_unloop(EV_A_ EVUNLOOP_ALL);
|
||||
resolve_int_cb(revents);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1647,9 +1654,6 @@ start_ss_local_server(profile_t profile)
|
||||
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);
|
||||
@@ -1657,7 +1661,6 @@ start_ss_local_server(profile_t profile)
|
||||
ev_signal_start(EV_DEFAULT, &sigterm_watcher);
|
||||
ev_signal_start(EV_DEFAULT, &sigchld_watcher);
|
||||
#ifndef __MINGW32__
|
||||
struct ev_signal sigusr1_watcher;
|
||||
ev_signal_init(&sigusr1_watcher, signal_cb, SIGUSR1);
|
||||
ev_signal_start(EV_DEFAULT, &sigusr1_watcher);
|
||||
#endif
|
||||
@@ -1746,13 +1749,6 @@ start_ss_local_server(profile_t profile)
|
||||
winsock_cleanup();
|
||||
#endif
|
||||
|
||||
ev_signal_stop(EV_DEFAULT, &sigint_watcher);
|
||||
ev_signal_stop(EV_DEFAULT, &sigterm_watcher);
|
||||
ev_signal_stop(EV_DEFAULT, &sigchld_watcher);
|
||||
#ifndef __MINGW32__
|
||||
ev_signal_stop(EV_DEFAULT, &sigusr1_watcher);
|
||||
#endif
|
||||
|
||||
// cannot reach here
|
||||
return 0;
|
||||
}
|
||||
|
||||
+8
-7
@@ -96,6 +96,10 @@ static int auth = 0;
|
||||
static int nofile = 0;
|
||||
#endif
|
||||
|
||||
static struct ev_signal sigint_watcher;
|
||||
static struct ev_signal sigterm_watcher;
|
||||
static struct ev_signal sigchld_watcher;
|
||||
|
||||
int
|
||||
getdestaddr(int fd, struct sockaddr_storage *destaddr)
|
||||
{
|
||||
@@ -758,6 +762,10 @@ 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);
|
||||
|
||||
keep_resolving = 0;
|
||||
ev_unloop(EV_A_ EVUNLOOP_ALL);
|
||||
}
|
||||
@@ -1025,9 +1033,6 @@ main(int argc, char **argv)
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGABRT, SIG_IGN);
|
||||
|
||||
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);
|
||||
@@ -1107,9 +1112,5 @@ 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;
|
||||
}
|
||||
|
||||
+7
-7
@@ -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;
|
||||
}
|
||||
|
||||
+8
-7
@@ -101,6 +101,10 @@ static int auth = 0;
|
||||
static int nofile = 0;
|
||||
#endif
|
||||
|
||||
static struct ev_signal sigint_watcher;
|
||||
static struct ev_signal sigterm_watcher;
|
||||
static struct ev_signal sigchld_watcher;
|
||||
|
||||
#ifndef __MINGW32__
|
||||
static int
|
||||
setnonblocking(int fd)
|
||||
@@ -719,6 +723,10 @@ 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);
|
||||
|
||||
keep_resolving = 0;
|
||||
ev_unloop(EV_A_ EVUNLOOP_ALL);
|
||||
}
|
||||
@@ -1025,9 +1033,6 @@ main(int argc, char **argv)
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGABRT, SIG_IGN);
|
||||
|
||||
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);
|
||||
@@ -1114,10 +1119,6 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user