mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 23:21:38 +01:00
Add PT_PROTO_FAILED_LAUNCH managed proxy state.
We used to try to terminate the managed proxy process even if it failed while launching. We introduce a new managed proxy state, to represent a *broken* and *not launched* proxy.
This commit is contained in:
parent
20be928fae
commit
572aa4ec44
2 changed files with 25 additions and 15 deletions
|
@ -22,7 +22,8 @@ static int set_managed_proxy_environment(char ***envp,
|
||||||
|
|
||||||
static INLINE int proxy_configuration_finished(const managed_proxy_t *mp);
|
static INLINE int proxy_configuration_finished(const managed_proxy_t *mp);
|
||||||
|
|
||||||
static void managed_proxy_destroy(managed_proxy_t *mp);
|
static void managed_proxy_destroy(managed_proxy_t *mp,
|
||||||
|
int also_terminate_process);
|
||||||
|
|
||||||
static void handle_finished_proxy(managed_proxy_t *mp);
|
static void handle_finished_proxy(managed_proxy_t *mp);
|
||||||
static void configure_proxy(managed_proxy_t *mp);
|
static void configure_proxy(managed_proxy_t *mp);
|
||||||
|
@ -242,6 +243,7 @@ proxy_prepare_for_restart(managed_proxy_t *mp)
|
||||||
tor_terminate_process(mp->process_handle);
|
tor_terminate_process(mp->process_handle);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* ??? */
|
||||||
memset(mp->process_handle, 0, sizeof(process_handle_t));
|
memset(mp->process_handle, 0, sizeof(process_handle_t));
|
||||||
|
|
||||||
/* destroy all its old transports. we no longer use them. */
|
/* destroy all its old transports. we no longer use them. */
|
||||||
|
@ -325,7 +327,8 @@ pt_configure_remaining_proxies(void)
|
||||||
log_debug(LD_CONFIG, "Configuring remaining managed proxies (%d)!",
|
log_debug(LD_CONFIG, "Configuring remaining managed proxies (%d)!",
|
||||||
unconfigured_proxies_n);
|
unconfigured_proxies_n);
|
||||||
SMARTLIST_FOREACH_BEGIN(managed_proxy_list, managed_proxy_t *, mp) {
|
SMARTLIST_FOREACH_BEGIN(managed_proxy_list, managed_proxy_t *, mp) {
|
||||||
tor_assert(mp->conf_state != PT_PROTO_BROKEN);
|
tor_assert(mp->conf_state != PT_PROTO_BROKEN ||
|
||||||
|
mp->conf_state != PT_PROTO_FAILED_LAUNCH);
|
||||||
|
|
||||||
if (mp->got_hup) {
|
if (mp->got_hup) {
|
||||||
mp->got_hup = 0;
|
mp->got_hup = 0;
|
||||||
|
@ -367,7 +370,7 @@ configure_proxy(managed_proxy_t *mp)
|
||||||
/* if we haven't launched the proxy yet, do it now */
|
/* if we haven't launched the proxy yet, do it now */
|
||||||
if (mp->conf_state == PT_PROTO_INFANT) {
|
if (mp->conf_state == PT_PROTO_INFANT) {
|
||||||
if (launch_managed_proxy(mp) < 0) { /* launch fail */
|
if (launch_managed_proxy(mp) < 0) { /* launch fail */
|
||||||
mp->conf_state = PT_PROTO_BROKEN;
|
mp->conf_state = PT_PROTO_FAILED_LAUNCH;
|
||||||
handle_finished_proxy(mp);
|
handle_finished_proxy(mp);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -419,7 +422,7 @@ configure_proxy(managed_proxy_t *mp)
|
||||||
/* if we haven't launched the proxy yet, do it now */
|
/* if we haven't launched the proxy yet, do it now */
|
||||||
if (mp->conf_state == PT_PROTO_INFANT) {
|
if (mp->conf_state == PT_PROTO_INFANT) {
|
||||||
if (launch_managed_proxy(mp) < 0) { /* launch fail */
|
if (launch_managed_proxy(mp) < 0) { /* launch fail */
|
||||||
mp->conf_state = PT_PROTO_BROKEN;
|
mp->conf_state = PT_PROTO_FAILED_LAUNCH;
|
||||||
handle_finished_proxy(mp);
|
handle_finished_proxy(mp);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -524,7 +527,8 @@ register_proxy(managed_proxy_t *mp)
|
||||||
|
|
||||||
/** Free memory allocated by managed proxy <b>mp</b>. */
|
/** Free memory allocated by managed proxy <b>mp</b>. */
|
||||||
static void
|
static void
|
||||||
managed_proxy_destroy(managed_proxy_t *mp)
|
managed_proxy_destroy(managed_proxy_t *mp,
|
||||||
|
int also_terminate_process)
|
||||||
{
|
{
|
||||||
if (mp->conf_state != PT_PROTO_COMPLETED)
|
if (mp->conf_state != PT_PROTO_COMPLETED)
|
||||||
SMARTLIST_FOREACH(mp->transports, transport_t *, t, transport_free(t));
|
SMARTLIST_FOREACH(mp->transports, transport_t *, t, transport_free(t));
|
||||||
|
@ -544,7 +548,7 @@ managed_proxy_destroy(managed_proxy_t *mp)
|
||||||
/* free the argv */
|
/* free the argv */
|
||||||
free_execve_args(mp->argv);
|
free_execve_args(mp->argv);
|
||||||
|
|
||||||
tor_process_destroy(mp->process_handle, 1);
|
tor_process_destroy(mp->process_handle, also_terminate_process);
|
||||||
|
|
||||||
tor_free(mp);
|
tor_free(mp);
|
||||||
}
|
}
|
||||||
|
@ -555,7 +559,10 @@ handle_finished_proxy(managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
switch (mp->conf_state) {
|
switch (mp->conf_state) {
|
||||||
case PT_PROTO_BROKEN: /* if broken: */
|
case PT_PROTO_BROKEN: /* if broken: */
|
||||||
managed_proxy_destroy(mp); /* annihilate it. */
|
managed_proxy_destroy(mp, 1); /* annihilate it. */
|
||||||
|
break;
|
||||||
|
case PT_PROTO_FAILED_LAUNCH:
|
||||||
|
managed_proxy_destroy(mp, 0);
|
||||||
break;
|
break;
|
||||||
case PT_PROTO_CONFIGURED: /* if configured correctly: */
|
case PT_PROTO_CONFIGURED: /* if configured correctly: */
|
||||||
register_proxy(mp); /* register its transports */
|
register_proxy(mp); /* register its transports */
|
||||||
|
@ -581,7 +588,8 @@ static INLINE int
|
||||||
proxy_configuration_finished(const managed_proxy_t *mp)
|
proxy_configuration_finished(const managed_proxy_t *mp)
|
||||||
{
|
{
|
||||||
return (mp->conf_state == PT_PROTO_CONFIGURED ||
|
return (mp->conf_state == PT_PROTO_CONFIGURED ||
|
||||||
mp->conf_state == PT_PROTO_BROKEN);
|
mp->conf_state == PT_PROTO_BROKEN ||
|
||||||
|
mp->conf_state == PT_PROTO_FAILED_LAUNCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This function is called when a proxy sends an {S,C}METHODS DONE message. */
|
/** This function is called when a proxy sends an {S,C}METHODS DONE message. */
|
||||||
|
@ -680,7 +688,8 @@ handle_proxy_line(const char *line, managed_proxy_t *mp)
|
||||||
return;
|
return;
|
||||||
} else if (!strcmpstart(line, SPAWN_ERROR_MESSAGE)) {
|
} else if (!strcmpstart(line, SPAWN_ERROR_MESSAGE)) {
|
||||||
log_warn(LD_GENERAL, "Could not launch managed proxy executable!");
|
log_warn(LD_GENERAL, "Could not launch managed proxy executable!");
|
||||||
goto err;
|
mp->conf_state = PT_PROTO_FAILED_LAUNCH;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_warn(LD_CONFIG, "Unknown line received by managed proxy. (%s)", line);
|
log_warn(LD_CONFIG, "Unknown line received by managed proxy. (%s)", line);
|
||||||
|
@ -1180,7 +1189,7 @@ pt_prepare_proxy_list_for_config_read(void)
|
||||||
SMARTLIST_FOREACH_BEGIN(managed_proxy_list, managed_proxy_t *, mp) {
|
SMARTLIST_FOREACH_BEGIN(managed_proxy_list, managed_proxy_t *, mp) {
|
||||||
/* Destroy unconfigured proxies. */
|
/* Destroy unconfigured proxies. */
|
||||||
if (mp->conf_state != PT_PROTO_COMPLETED) {
|
if (mp->conf_state != PT_PROTO_COMPLETED) {
|
||||||
managed_proxy_destroy(mp);
|
managed_proxy_destroy(mp, 1);
|
||||||
unconfigured_proxies_n--;
|
unconfigured_proxies_n--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1209,7 +1218,7 @@ sweep_proxy_list(void)
|
||||||
SMARTLIST_FOREACH_BEGIN(managed_proxy_list, managed_proxy_t *, mp) {
|
SMARTLIST_FOREACH_BEGIN(managed_proxy_list, managed_proxy_t *, mp) {
|
||||||
if (mp->marked_for_removal) {
|
if (mp->marked_for_removal) {
|
||||||
SMARTLIST_DEL_CURRENT(managed_proxy_list, mp);
|
SMARTLIST_DEL_CURRENT(managed_proxy_list, mp);
|
||||||
managed_proxy_destroy(mp);
|
managed_proxy_destroy(mp, 1);
|
||||||
}
|
}
|
||||||
} SMARTLIST_FOREACH_END(mp);
|
} SMARTLIST_FOREACH_END(mp);
|
||||||
}
|
}
|
||||||
|
@ -1224,7 +1233,7 @@ pt_free_all(void)
|
||||||
free them. Otherwise, it hasn't registered its transports yet
|
free them. Otherwise, it hasn't registered its transports yet
|
||||||
and we should free them here. */
|
and we should free them here. */
|
||||||
SMARTLIST_FOREACH(managed_proxy_list, managed_proxy_t *, mp,
|
SMARTLIST_FOREACH(managed_proxy_list, managed_proxy_t *, mp,
|
||||||
managed_proxy_destroy(mp));
|
managed_proxy_destroy(mp, 1));
|
||||||
|
|
||||||
smartlist_free(managed_proxy_list);
|
smartlist_free(managed_proxy_list);
|
||||||
managed_proxy_list=NULL;
|
managed_proxy_list=NULL;
|
||||||
|
|
|
@ -36,7 +36,8 @@ enum pt_proto_state {
|
||||||
PT_PROTO_ACCEPTING_METHODS, /* accepting methods */
|
PT_PROTO_ACCEPTING_METHODS, /* accepting methods */
|
||||||
PT_PROTO_CONFIGURED, /* configured successfully */
|
PT_PROTO_CONFIGURED, /* configured successfully */
|
||||||
PT_PROTO_COMPLETED, /* configure and registered its transports */
|
PT_PROTO_COMPLETED, /* configure and registered its transports */
|
||||||
PT_PROTO_BROKEN
|
PT_PROTO_BROKEN, /* broke during the protocol */
|
||||||
|
PT_PROTO_FAILED_LAUNCH /* failed while launching */
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Structure containing information of a managed proxy. */
|
/** Structure containing information of a managed proxy. */
|
||||||
|
|
Loading…
Add table
Reference in a new issue