diff options
author | Alexander Færøy <ahf@torproject.org> | 2018-11-23 05:43:34 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-12-17 16:39:28 -0500 |
commit | b0d268a82264f28f6b78f734d45a13e8272e70ea (patch) | |
tree | f97fa4faa5e22583f4c773d6af0039a2715abcef /src/lib/process | |
parent | 4f611a1df70d2c5e4cb6261f75c1b82c9ed04598 (diff) | |
download | tor-b0d268a82264f28f6b78f734d45a13e8272e70ea.tar.gz tor-b0d268a82264f28f6b78f734d45a13e8272e70ea.zip |
Add process_reset_environment() to the Process subsystem.
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
Diffstat (limited to 'src/lib/process')
-rw-r--r-- | src/lib/process/process.c | 17 | ||||
-rw-r--r-- | src/lib/process/process.h | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/process/process.c b/src/lib/process/process.c index 657b319f54..915217e132 100644 --- a/src/lib/process/process.c +++ b/src/lib/process/process.c @@ -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 diff --git a/src/lib/process/process.h b/src/lib/process/process.h index c6b733a065..6092c2da7d 100644 --- a/src/lib/process/process.h +++ b/src/lib/process/process.h @@ -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); |