diff --git a/changes/bug5604 b/changes/bug5604 new file mode 100644 index 0000000000..4c72f3c859 --- /dev/null +++ b/changes/bug5604 @@ -0,0 +1,4 @@ + o Minor bugfixes: + - Don't try to open non-control listeners when DisableNetwork is set. + Previousy, we'd open all listeners, then immediately close them. + Fixes bug 5604; bugfix on 0.2.3.9-alpha. diff --git a/src/or/config.c b/src/or/config.c index 27aa8a2f23..8a19ed6d44 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -1138,7 +1138,8 @@ options_act_reversible(const or_options_t *old_options, char **msg) * networking is disabled, this will close all but the control listeners, * but disable those. */ if (!we_are_hibernating()) { - if (retry_all_listeners(replaced_listeners, new_listeners) < 0) { + if (retry_all_listeners(replaced_listeners, new_listeners, + options->DisableNetwork) < 0) { *msg = tor_strdup("Failed to bind one of the listener ports."); goto rollback; } diff --git a/src/or/connection.c b/src/or/connection.c index 0c970cc3b4..eb8b840eb7 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -1812,17 +1812,28 @@ connection_read_proxy_handshake(connection_t *conn) * entry in ports. Add to new_conns new every connection we * launch. * + * If control_listeners_only is true, then we only open control + * listeners, and we do not remove any noncontrol listeners from old_conns. + * * Return 0 on success, -1 on failure. **/ static int retry_listener_ports(smartlist_t *old_conns, const smartlist_t *ports, - smartlist_t *new_conns) + smartlist_t *new_conns, + int control_listeners_only) { smartlist_t *launch = smartlist_new(); int r = 0; - smartlist_add_all(launch, ports); + if (control_listeners_only) { + SMARTLIST_FOREACH(ports, port_cfg_t *, p, { + if (p->type == CONN_TYPE_CONTROL_LISTENER) + smartlist_add(launch, p); + }); + } else { + smartlist_add_all(launch, ports); + } /* Iterate through old_conns, comparing it to launch: remove from both lists * each pair of elements that corresponds to the same port. */ @@ -1922,10 +1933,13 @@ retry_listener_ports(smartlist_t *old_conns, * * Add all old conns that should be closed to replaced_conns. * Add all new connections to new_conns. + * + * If close_all_noncontrol is true, then we only open control + * listeners, and we close all other listeners. */ int retry_all_listeners(smartlist_t *replaced_conns, - smartlist_t *new_conns) + smartlist_t *new_conns, int close_all_noncontrol) { smartlist_t *listeners = smartlist_new(); const or_options_t *options = get_options(); @@ -1940,7 +1954,8 @@ retry_all_listeners(smartlist_t *replaced_conns, if (retry_listener_ports(listeners, get_configured_ports(), - new_conns) < 0) + new_conns, + close_all_noncontrol) < 0) retval = -1; /* Any members that were still in 'listeners' don't correspond to diff --git a/src/or/connection.h b/src/or/connection.h index c4b8bf8abe..bdeefa2549 100644 --- a/src/or/connection.h +++ b/src/or/connection.h @@ -64,7 +64,8 @@ int get_proxy_addrport(tor_addr_t *addr, uint16_t *port, int *proxy_type, const connection_t *conn); int retry_all_listeners(smartlist_t *replaced_conns, - smartlist_t *new_conns); + smartlist_t *new_conns, + int close_all_noncontrol); void connection_mark_all_noncontrol_listeners(void); void connection_mark_all_noncontrol_connections(void); diff --git a/src/or/main.c b/src/or/main.c index 8308b3a238..ab537728f2 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1428,7 +1428,7 @@ run_scheduled_events(time_t now) /** 3d. And every 60 seconds, we relaunch listeners if any died. */ if (!net_is_disabled() && time_to_check_listeners < now) { - retry_all_listeners(NULL, NULL); + retry_all_listeners(NULL, NULL, 0); time_to_check_listeners = now+60; }