Mercurial > dovecot > core-2.2
changeset 12412:e60061623012
Added env_get_environ_p() as more portable way of accessing environ variable.
Implemented with OS X using _NSGetEnviron().
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 09 Nov 2010 21:42:58 +0000 |
parents | f89b4de6688d |
children | 67fbf09d3fa5 |
files | src/lib-settings/settings-parser.c src/lib/env-util.c src/lib/env-util.h src/lib/process-title.c |
diffstat | 4 files changed, 25 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-settings/settings-parser.c Tue Nov 09 21:17:15 2010 +0000 +++ b/src/lib-settings/settings-parser.c Tue Nov 09 21:42:58 2010 +0000 @@ -5,6 +5,7 @@ #include "hash.h" #include "network.h" #include "istream.h" +#include "env-util.h" #include "execv-const.h" #include "str.h" #include "strescape.h" @@ -942,7 +943,7 @@ int settings_parse_environ(struct setting_parser_context *ctx) { - extern char **environ; + char **environ = *env_get_environ_p(); ARRAY_TYPE(string) sorted_envs_arr; const char *key, *value; char *const *sorted_envs;
--- a/src/lib/env-util.c Tue Nov 09 21:17:15 2010 +0000 +++ b/src/lib/env-util.c Tue Nov 09 21:42:58 2010 +0000 @@ -5,6 +5,9 @@ #include "env-util.h" #include <stdlib.h> +#ifdef __APPLE__ +# include <crt_externs.h> +#endif struct env_backup { pool_t pool; @@ -106,8 +109,8 @@ struct env_backup *env_backup_save(void) { + char **environ = *env_get_environ_p(); struct env_backup *env; - extern char **environ; unsigned int i, count; pool_t pool; @@ -141,6 +144,17 @@ pool_unref(&env->pool); } +char ***env_get_environ_p(void) +{ +#ifdef __APPLE__ + return _NSGetEnviron(); +#else + extern char **environ; + + return &environ; +#endif +} + void env_deinit(void) { if (env_pool != NULL)
--- a/src/lib/env-util.h Tue Nov 09 21:17:15 2010 +0000 +++ b/src/lib/env-util.h Tue Nov 09 21:42:58 2010 +0000 @@ -18,6 +18,10 @@ /* Free the memory used by environment backup. */ void env_backup_free(struct env_backup **env); +/* Returns the value of "&environ". This is more portable than using it + directly. */ +char ***env_get_environ_p(void); + /* Free all memory used by env_put() function. Environment must not be accessed afterwards. */ void env_deinit(void);
--- a/src/lib/process-title.c Tue Nov 09 21:17:15 2010 +0000 +++ b/src/lib/process-title.c Tue Nov 09 21:42:58 2010 +0000 @@ -1,6 +1,7 @@ /* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "env-util.h" #include "process-title.h" #include <stdlib.h> /* NetBSD, OpenBSD */ @@ -115,12 +116,12 @@ void process_title_init(char **argv[]) { #ifdef PROCTITLE_HACK - extern char **environ; + char ***environ_p = env_get_environ_p(); char **orig_argv = *argv; - char **orig_environ = environ; + char **orig_environ = *environ_p; *argv = argv_dup(orig_argv, &argv_memblock); - environ = argv_dup(orig_environ, &environ_memblock); + *environ_p = argv_dup(orig_environ, &environ_memblock); proctitle_hack_init(orig_argv, orig_environ); #endif process_name = (*argv)[0];