]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Clean up how we arrange for environ to be declared
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 7 Oct 2016 16:24:31 +0000 (17:24 +0100)
committerSimon McVittie <smcv@debian.org>
Thu, 13 Oct 2016 16:20:34 +0000 (17:20 +0100)
Annoyingly, the POSIX way to declare environ (as
"extern char **environ") is a redundant declaration in glibc with
_GNU_SOURCE; work around that.

We also have a workaround for _NSGetEnviron() needing to be used
instead of direct access to environ in at least some circumstances on
Mac OS. Attempt to sync that up between all the files that use environ,
consistently sorting the most special special-cases first (Windows
for files that are compiled there, then Mac, then GNU, with
lowest-common-denominator POSIX last).

The affected files are already OS-specific, so I'm not bothering to
introduce a nicer or higher-level API for this.

Based on the best bits of an earlier patch from me, and an earlier
patch from Thomas Zimmermann.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97357

configure.ac
dbus/dbus-spawn.c
dbus/dbus-sysdeps-util.c
dbus/dbus-sysdeps.c
tools/dbus-update-activation-environment.c

index 7b20e11c96eb18fe5da6f7e0b7edb8bc067e333e..20d41a703bb0b1fc98d60b38d4c64b9dc5a0e884 100644 (file)
@@ -491,6 +491,10 @@ case $host_os in
                ;;
 esac
 
+# As a GNU extension, glibc declares environ in unistd.h, which is one of
+# the AC_INCLUDES_DEFAULT.
+AC_CHECK_DECLS([environ])
+
 dnl **********************************
 dnl *** va_copy checks (from GLib) ***
 dnl **********************************
index df6eafd91326bfb9f3ae1ab107cdf29cfe6963a9..0be8800c329768bea6ef7c78e08767db9976a52b 100644 (file)
 #include <systemd/sd-journal.h>
 #endif
 
+#if defined(__APPLE__)
+# include <crt_externs.h>
+# define environ (*_NSGetEnviron ())
+#elif !HAVE_DECL_ENVIRON
 extern char **environ;
+#endif
 
 /**
  * @addtogroup DBusInternalsUtils
index f35c966600a0f2244519a642ac670a7f9eab2105..44cc6a23aafb240e2cf58fdd939e3f725ca77500 100644 (file)
@@ -35,6 +35,8 @@
 #elif (defined __APPLE__)
 # include <crt_externs.h>
 # define environ (*_NSGetEnviron())
+#elif HAVE_DECL_ENVIRON && defined(HAVE_UNISTD_H)
+# include <unistd.h>
 #else
 extern char **environ;
 #endif
index c58377bd4053e017183585f6ccbabfa660d660af..d1a96d12fcedf93964678161c4297413e809bf2b 100644 (file)
@@ -52,6 +52,8 @@
 #elif (defined __APPLE__)
 # include <crt_externs.h>
 # define environ (*_NSGetEnviron())
+#elif HAVE_DECL_ENVIRON && defined(HAVE_UNISTD_H)
+# include <unistd.h>
 #else
 extern char **environ;
 #endif
index 160ac5d0ae50017a9520eeebc6bbd66d24b2837f..452e50532c16c201f99683496be9c6a2306657ce 100644 (file)
 #ifdef DBUS_WIN
 /* The Windows C runtime uses a different name */
 #define environ _environ
+#elif defined(__APPLE__)
+# include <crt_externs.h>
+# define environ (*_NSGetEnviron ())
+#elif HAVE_DECL_ENVIRON && defined(HAVE_UNISTD_H)
+# include <unistd.h>
 #else
-/* apparently this is the portable way to get the entire environment...
- * GNU platforms also put it in unistd.h but that's not portable */
 extern char **environ;
 #endif