diff options
author | Sebastian Hahn <sebastian@torproject.org> | 2012-02-14 12:21:03 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-02-14 11:18:39 -0500 |
commit | efb7b9dec135594718b765234bc1f745855f60d2 (patch) | |
tree | cf8b42d4c5c221354e0b1bf97a7a6ef8e9f42056 /src/common | |
parent | efcdc930fb02d471ef1a5f4c09a30ea512ca5a8b (diff) | |
download | tor-efb7b9dec135594718b765234bc1f745855f60d2.tar tor-efb7b9dec135594718b765234bc1f745855f60d2.tar.gz |
Use _NSGetEnviron() instead of environ where required
OS X would otherwise crash with a segfault when linked statically to
some libraries.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.c | 23 | ||||
-rw-r--r-- | src/common/compat.h | 2 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 64c06681d..f25a8ac3b 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -51,6 +51,9 @@ #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> #endif +#ifdef HAVE_CRT_EXTERNS_H +#include <crt_externs.h> +#endif #ifndef HAVE_GETTIMEOFDAY #ifdef HAVE_FTIME @@ -1659,6 +1662,26 @@ make_path_absolute(char *fname) #endif } +#ifndef HAVE__NSGETENVIRON +/* FreeBSD needs this; it doesn't seem to hurt other platforms. */ +extern char **environ; +#endif + +/** Return the current environment. This is a portable replacement for + * 'environ'. */ +char ** +get_environment(void) +{ +#ifdef HAVE__NSGETENVIRON + /* This is for compatibility between OSX versions. Otherwise (for example) + * when we do a mostly-static build on OSX 10.7, the resulting binary won't + * work on OSX 10.6. */ + return *_NSGetEnviron(); +#else + return environ; +#endif +} + /** Set *addr to the IP address (in dotted-quad notation) stored in c. * Return 1 on success, 0 if c is badly formatted. (Like inet_aton(c,addr), * but works on Windows and Solaris.) diff --git a/src/common/compat.h b/src/common/compat.h index fa1ef90eb..65e6cb49e 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -581,6 +581,8 @@ char *get_user_homedir(const char *username); int get_parent_directory(char *fname); char *make_path_absolute(char *fname); +char **get_environment(void); + int spawn_func(void (*func)(void *), void *data); void spawn_exit(void) ATTR_NORETURN; |