]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add process_reset_environment() to the Process subsystem.
authorAlexander Færøy <ahf@torproject.org>
Fri, 23 Nov 2018 04:43:34 +0000 (05:43 +0100)
committerNick Mathewson <nickm@torproject.org>
Mon, 17 Dec 2018 21:39:28 +0000 (16:39 -0500)
This patch adds a new function that allows us to reset the environment
of a given process_t with a list of key/value pairs.

See: https://bugs.torproject.org/28179

src/lib/process/process.c
src/lib/process/process.h

index 657b319f542263a067f01416931935644317091f..915217e132daa8733243c5311a2ecd5891e06dc3 100644 (file)
@@ -441,6 +441,23 @@ process_get_argv(const process_t *process)
   return argv;
 }
 
+/** This function clears the internal environment and copies over every string
+ * from <b>env</b> as the new environment. */
+void
+process_reset_environment(process_t *process, const smartlist_t *env)
+{
+  tor_assert(process);
+  tor_assert(env);
+
+  /* Cleanup old environment. */
+  SMARTLIST_FOREACH(process->environment, char *, x, tor_free(x));
+  smartlist_free(process->environment);
+  process->environment = smartlist_new();
+
+  SMARTLIST_FOREACH(env, char *, x,
+                    smartlist_add(process->environment, tor_strdup(x)));
+}
+
 /** Set the given <b>key</b>/<b>value</b> pair as environment variable in the
  * given process. */
 void
index c6b733a065c8bae52dbae3e01acc2badf70ba107..6092c2da7d5778b7657d146b60f36d19f34bde7d 100644 (file)
@@ -83,6 +83,7 @@ void process_append_argument(process_t *process, const char *argument);
 const smartlist_t *process_get_arguments(const process_t *process);
 char **process_get_argv(const process_t *process);
 
+void process_reset_environment(process_t *process, const smartlist_t *env);
 void process_set_environment(process_t *process,
                              const char *key,
                              const char *value);