Ver código fonte

Pass process_environment_t * to tor_spawn_background

Now tor_spawn_background's prototype is OS-independent.
Robert Ransom 14 anos atrás
pai
commit
c0808b795f
3 arquivos alterados com 10 adições e 21 exclusões
  1. 4 8
      src/common/util.c
  2. 4 11
      src/common/util.h
  3. 2 2
      src/or/transports.c

+ 4 - 8
src/common/util.c

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

+ 4 - 11
src/common/util.h

@@ -365,12 +365,9 @@ void tor_check_port_forwarding(const char *filename,
                                int dir_port, int or_port, time_t now);
                                int dir_port, int or_port, time_t now);
 
 
 typedef struct process_handle_t process_handle_t;
 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,
 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);
                          process_handle_t **process_handle_out);
 
 
 #define SPAWN_ERROR_MESSAGE "ERR: Failed to spawn background process - code "
 #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". */
    * NUL-terminated strings of the form "NAME=VALUE". */
   char *windows_environment_block;
   char *windows_environment_block;
   /** A pointer to a NULL-terminated array of pointers to
   /** 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);
 process_environment_t *process_environment_make(struct smartlist_t *env_vars);
 void process_environment_free(process_environment_t *env);
 void process_environment_free(process_environment_t *env);

+ 2 - 2
src/or/transports.c

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