Pass process_environment_t * to tor_spawn_background

Now tor_spawn_background's prototype is OS-independent.
This commit is contained in:
Robert Ransom 2012-02-13 00:59:49 -08:00 committed by Nick Mathewson
parent ee3a49d6ed
commit c0808b795f
3 changed files with 10 additions and 21 deletions

View file

@ -3313,11 +3313,7 @@ process_handle_new(void)
*/
int
tor_spawn_background(const char *const filename, const char **argv,
#ifdef _WIN32
LPVOID envp,
#else
const char **envp,
#endif
process_environment_t *env,
process_handle_t **process_handle_out)
{
#ifdef _WIN32
@ -3398,7 +3394,7 @@ tor_spawn_background(const char *const filename, const char **argv,
/*(TODO: set CREATE_NEW CONSOLE/PROCESS_GROUP to make GetExitCodeProcess()
* work?) */
0, // creation flags
envp, // use parent's environment
(env==NULL) ? NULL : env->windows_environment_block,
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&(process_handle->pid)); // receives PROCESS_INFORMATION
@ -3528,8 +3524,8 @@ tor_spawn_background(const char *const filename, const char **argv,
/* Call the requested program. We need the cast because
execvp doesn't define argv as const, even though it
does not modify the arguments */
if (envp)
execve(filename, (char *const *) argv, (char*const*)envp);
if (env)
execve(filename, (char *const *) argv, env->unixoid_environment_block);
else
execvp(filename, (char *const *) argv);

View file

@ -365,12 +365,9 @@ void tor_check_port_forwarding(const char *filename,
int dir_port, int or_port, time_t now);
typedef struct process_handle_t process_handle_t;
typedef struct process_environment_t process_environment_t;
int tor_spawn_background(const char *const filename, const char **argv,
#ifdef _WIN32
LPVOID envp,
#else
const char **envp,
#endif
process_environment_t *env,
process_handle_t **process_handle_out);
#define SPAWN_ERROR_MESSAGE "ERR: Failed to spawn background process - code "
@ -386,13 +383,9 @@ struct process_environment_t {
* NUL-terminated strings of the form "NAME=VALUE". */
char *windows_environment_block;
/** A pointer to a NULL-terminated array of pointers to
* NUL-terminated strings of the form "NAME=VALUE".
*
* XXXX This should have type char **, but tor_spawn_background's
* prototype is incorrect. */
const char **unixoid_environment_block;
* NUL-terminated strings of the form "NAME=VALUE". */
char **unixoid_environment_block;
};
typedef struct process_environment_t process_environment_t;
process_environment_t *process_environment_make(struct smartlist_t *env_vars);
void process_environment_free(process_environment_t *env);

View file

@ -288,12 +288,12 @@ launch_managed_proxy(managed_proxy_t *mp)
/* Passing NULL as lpApplicationName makes Windows search for the .exe */
retval = tor_spawn_background(NULL,
(const char **)mp->argv,
env->windows_environment_block,
env,
&mp->process_handle);
#else
retval = tor_spawn_background(mp->argv[0],
(const char **)mp->argv,
env->unixoid_environment_block,
env,
&mp->process_handle);
#endif