Browse Source

Fix #690

pull/691/head
Max Lv 8 years ago
parent
commit
55dea8b973
4 changed files with 40 additions and 8 deletions
  1. 23
      src/local.c
  2. 10
      src/netutils.c
  3. 7
      src/redir.c
  4. 8
      src/tunnel.c

23
src/local.c

@ -80,6 +80,8 @@
#endif
int verbose = 0;
int keep_resolving = 1;
#ifdef ANDROID
int vpn = 0;
uint64_t tx = 0;
@ -969,6 +971,10 @@ void accept_cb(EV_P_ ev_io *w, int revents)
ev_io_start(EV_A_ & server->recv_ctx->io);
}
void resolve_int_cb(int dummy) {
keep_resolving = 0;
}
#ifndef LIB_ONLY
int main(int argc, char **argv)
{
@ -1185,15 +1191,9 @@ int main(int argc, char **argv)
// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, SIG_IGN);
signal(SIGINT, resolve_int_cb);
#endif
struct ev_signal sigint_watcher;
struct ev_signal sigterm_watcher;
ev_signal_init(&sigint_watcher, signal_cb, SIGINT);
ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM);
ev_signal_start(EV_DEFAULT, &sigint_watcher);
ev_signal_start(EV_DEFAULT, &sigterm_watcher);
// Setup keys
LOGI("initializing ciphers... %s", method);
int m = enc_init(password, method);
@ -1217,6 +1217,15 @@ int main(int argc, char **argv)
listen_ctx.iface = iface;
listen_ctx.method = m;
// Setup signal handler
struct ev_signal sigint_watcher;
struct ev_signal sigterm_watcher;
ev_signal_init(&sigint_watcher, signal_cb, SIGINT);
ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM);
ev_signal_start(EV_DEFAULT, &sigint_watcher);
ev_signal_start(EV_DEFAULT, &sigterm_watcher);
struct ev_loop *loop = EV_DEFAULT;
// Setup socket

10
src/netutils.c

@ -54,6 +54,10 @@
extern int verbose;
#if defined(MODULE_LOCAL)
extern int keep_resolving;
#endif
int set_reuseport(int socket)
{
int opt = 1;
@ -136,7 +140,11 @@ ssize_t get_sockaddr(char *host, char *port, struct sockaddr_storage *storage, i
for (i = 1; i < 8; i++) {
err = getaddrinfo(host, port, &hints, &result);
if (!block || !err) {
#if defined(MODULE_LOCAL)
if (!keep_resolving)
break;
#endif
if ((!block || !err)) {
break;
} else {
sleep(pow(2, i));

7
src/redir.c

@ -83,6 +83,7 @@ static void free_server(server_t *server);
static void close_and_free_server(EV_P_ server_t *server);
int verbose = 0;
int keep_resolving = 1;
static int mode = TCP_ONLY;
static int auth = 0;
@ -669,6 +670,11 @@ static void accept_cb(EV_P_ ev_io *w, int revents)
ev_io_start(EV_A_ & server->recv_ctx->io);
}
void signal_cb(int dummy) {
keep_resolving = 0;
exit(-1);
}
int main(int argc, char **argv)
{
int i, c;
@ -846,6 +852,7 @@ int main(int argc, char **argv)
// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, SIG_IGN);
signal(SIGINT, signal_cb);
// Setup keys
LOGI("initializing ciphers... %s", method);

8
src/tunnel.c

@ -90,7 +90,9 @@ static void close_and_free_server(EV_P_ server_t *server);
int vpn = 0;
char *prefix;
#endif
int verbose = 0;
int keep_resolving = 1;
static int mode = TCP_ONLY;
static int auth = 0;
@ -677,6 +679,11 @@ static void accept_cb(EV_P_ ev_io *w, int revents)
}
}
void signal_cb(int dummy) {
keep_resolving = 0;
exit(-1);
}
int main(int argc, char **argv)
{
int i, c;
@ -889,6 +896,7 @@ int main(int argc, char **argv)
// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, SIG_IGN);
signal(SIGINT, signal_cb);
#endif
// Setup keys

Loading…
Cancel
Save