]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add get_current_process_environment_variables
authorRobert Ransom <rransom.8774@gmail.com>
Mon, 13 Feb 2012 04:34:52 +0000 (20:34 -0800)
committerNick Mathewson <nickm@torproject.org>
Fri, 17 Feb 2012 16:42:19 +0000 (11:42 -0500)
src/common/util.c
src/common/util.h

index 5c3a85ec23a09c7dedb0ff8783e42969b6b923db..02a638e4ca5ea85a35a8972e9a55b00bb9f1197a 100644 (file)
@@ -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
index 3989cb4a1bd0b838f9d9a21186ac467badbe726e..f4854460695a5b9c3b2e565da28ad43858320efa 100644 (file)
@@ -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 */