aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ransom <rransom.8774@gmail.com>2012-02-12 20:34:52 -0800
committerNick Mathewson <nickm@torproject.org>2012-02-17 11:42:19 -0500
commit0ba93e184ad6216f886d7347dd81fe08edbb99c7 (patch)
tree49fd22cf4d67bbdec56fc615cd0fde5e7e29c290
parent98cec14982718d71e1a7b001f8a9a73c3bf0800b (diff)
downloadtor-0ba93e184ad6216f886d7347dd81fe08edbb99c7.tar
tor-0ba93e184ad6216f886d7347dd81fe08edbb99c7.tar.gz
Add get_current_process_environment_variables
-rw-r--r--src/common/util.c21
-rw-r--r--src/common/util.h2
2 files changed, 23 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 5c3a85ec2..02a638e4c 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -3832,6 +3832,27 @@ process_environment_make(struct smartlist_t *env_vars)
return env;
}
+/** Return a newly allocated smartlist containing every variable in
+ * this process's environment, as a NUL-terminated string of the form
+ * "NAME=VALUE". Note that on some/many/most/all OSes, the parent
+ * process can put strings not of that form in our environment;
+ * callers should try to not get crashed by that.
+ *
+ * The returned strings are statically allocated, and must be treated
+ * as read-only. */
+struct smartlist_t *
+get_current_process_environment_variables(void)
+{
+ smartlist_t *sl = smartlist_new();
+
+ char **environ_tmp; /* Not const char ** ? Really? */
+ for (environ_tmp = environ; *environ_tmp; ++environ_tmp) {
+ smartlist_add(sl, (void *)(*environ_tmp));
+ }
+
+ return sl;
+}
+
#ifdef _WIN32
/** Read from a handle <b>h</b> into <b>buf</b>, up to <b>count</b> bytes. If
* <b>hProcess</b> is NULL, the function will return immediately if there is
diff --git a/src/common/util.h b/src/common/util.h
index 3989cb4a1..f48544606 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -394,6 +394,8 @@ 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);
+struct smartlist_t *get_current_process_environment_variables(void);
+
/* Values of process_handle_t.status. PROCESS_STATUS_NOTRUNNING must be
* 0 because tor_check_port_forwarding depends on this being the initial
* statue of the static instance of process_handle_t */