diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-02-12 23:40:23 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-02-12 23:40:23 -0500 |
commit | 2aa1a6baa320d2d9a63d5ed3222ea95ef5ac00dc (patch) | |
tree | fce0ce258a5ec8bdfcb9b9d943d0e4570a6796dd /src | |
parent | 15309cbc49135f01041f66453d29e8fb2fdfd5e8 (diff) | |
parent | 93414707aec510c253cf150b654b04dab45cf9e9 (diff) | |
download | tor-2aa1a6baa320d2d9a63d5ed3222ea95ef5ac00dc.tar tor-2aa1a6baa320d2d9a63d5ed3222ea95ef5ac00dc.tar.gz |
Merge branch 'bug5082_squashed'
Diffstat (limited to 'src')
-rw-r--r-- | src/or/transports.c | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/src/or/transports.c b/src/or/transports.c index 15d96ca99..7bdb88aed 100644 --- a/src/or/transports.c +++ b/src/or/transports.c @@ -95,7 +95,7 @@ static void set_managed_proxy_environment(LPVOID *envp, const managed_proxy_t *mp); #else -static int set_managed_proxy_environment(char ***envp, +static void set_managed_proxy_environment(char ***envp, const managed_proxy_t *mp); #endif @@ -129,8 +129,8 @@ static INLINE void free_execve_args(char **arg); #define SMALLEST_MANAGED_LINE_SIZE 9 /** Number of environment variables for managed proxy clients/servers. */ -#define ENVIRON_SIZE_CLIENT 5 -#define ENVIRON_SIZE_SERVER 8 +#define ENVIRON_SIZE_CLIENT 3 +#define ENVIRON_SIZE_SERVER 6 /** The first and only supported - at the moment - configuration protocol version. */ @@ -305,12 +305,8 @@ launch_managed_proxy(managed_proxy_t *mp) char **envp=NULL; /* prepare the environment variables for the managed proxy */ - if (set_managed_proxy_environment(&envp, mp) < 0) { - log_warn(LD_GENERAL, "Could not setup the environment of " - "the managed proxy at '%s'.", mp->argv[0]); - free_execve_args(envp); - return -1; - } + set_managed_proxy_environment(&envp, mp); + tor_assert(envp); retval = tor_spawn_background(mp->argv[0], (const char **)mp->argv, (const char **)envp, &mp->process_handle); @@ -1077,10 +1073,12 @@ set_managed_proxy_environment(LPVOID *envp, const managed_proxy_t *mp) #else /* _WIN32 */ +extern char **environ; + /** Prepare the environment <b>envp</b> of managed proxy <b>mp</b>. * <b>envp</b> is allocated on the heap and should be freed by the * caller after its use. */ -static int +static void set_managed_proxy_environment(char ***envp, const managed_proxy_t *mp) { const or_options_t *options = get_options(); @@ -1088,27 +1086,30 @@ set_managed_proxy_environment(char ***envp, const managed_proxy_t *mp) char *state_loc=NULL; char *transports_to_launch=NULL; char *bindaddr=NULL; - char *home_env=NULL; - char *path_env=NULL; + int environ_size=0; + char **environ_tmp = environ; - int r = -1; int n_envs = mp->is_server ? ENVIRON_SIZE_SERVER : ENVIRON_SIZE_CLIENT; + while (*environ_tmp) { + environ_size++; + environ_tmp++; + } + environ_tmp = environ; + /* allocate enough space for our env. vars and a NULL pointer */ - *envp = tor_malloc(sizeof(char*)*(n_envs+1)); + *envp = tor_malloc(sizeof(char*)*(environ_size+n_envs+1)); tmp = *envp; state_loc = get_datadir_fname("pt_state/"); /* XXX temp */ transports_to_launch = smartlist_join_strings(mp->transports_to_launch, ",", 0, NULL); - home_env = getenv("HOME"); - path_env = getenv("PATH"); - if (!home_env || !path_env) - goto done; + while (*environ_tmp) { + *tmp = tor_strdup(*environ_tmp); + tmp++, environ_tmp++; + } - tor_asprintf(tmp++, "HOME=%s", home_env); - tor_asprintf(tmp++, "PATH=%s", path_env); tor_asprintf(tmp++, "TOR_PT_STATE_LOCATION=%s", state_loc); tor_asprintf(tmp++, "TOR_PT_MANAGED_TRANSPORT_VER=1"); /* temp */ if (mp->is_server) { @@ -1124,14 +1125,9 @@ set_managed_proxy_environment(char ***envp, const managed_proxy_t *mp) } *tmp = NULL; - r = 0; - - done: tor_free(state_loc); tor_free(transports_to_launch); tor_free(bindaddr); - - return r; } #endif /* _WIN32 */ |