]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added env_get_environ_p() as more portable way of accessing environ variable.
authorTimo Sirainen <tss@iki.fi>
Tue, 9 Nov 2010 21:42:58 +0000 (21:42 +0000)
committerTimo Sirainen <tss@iki.fi>
Tue, 9 Nov 2010 21:42:58 +0000 (21:42 +0000)
Implemented with OS X using _NSGetEnviron().

src/lib-settings/settings-parser.c
src/lib/env-util.c
src/lib/env-util.h
src/lib/process-title.c

index 55f0359857a8a44b34df9b0e0b843c7f63d291c1..bfdd57986df7f7cbd64b22679370a569257e6844 100644 (file)
@@ -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 @@ static int environ_cmp(char *const *s1, char *const *s2)
 
 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;
index 467487138d3507493cd7baa8e0005af33e36073f..12836b135c049afe0dd1f53d4d38977f84bb194e 100644 (file)
@@ -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 @@ void env_clean_except(const char *const preserve_envs[])
 
 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 @@ void env_backup_free(struct env_backup **_env)
        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)
index def2fe91ed83b915a4161ee4a1ac19636bea0514..f793da8bd42c7b0e50928aafedd0c80ef49522b4 100644 (file)
@@ -18,6 +18,10 @@ void env_backup_restore(struct env_backup *env);
 /* 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);
index e7bfa1390e295c4e6a5b2cf4fad7f293330be9a9..5ccf34bfb5be45cae10e75c92177654eb3fbfe57 100644 (file)
@@ -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 @@ static void proctitle_hack_set(const char *title)
 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];