Richard W.M. Jones
2020-Apr-28 15:43 UTC
[Libguestfs] [PATCH nbdkit] freebsd, openbsd: Add an extern decl for environ.
--- configure.ac | 24 ++++++++++++++++++++++++ plugins/sh/call.c | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/configure.ac b/configure.ac index cdddae73..9b925539 100644 --- a/configure.ac +++ b/configure.ac @@ -266,6 +266,30 @@ test (int a) ] ) +dnl 'environ' is not always declared in public header files: +dnl Linux => <unistd.h> Haiku => <stdlib.h> +dnl FreeBSD & OpenBSD => not declared +dnl On platforms where it's not declared we must add an extern decl. +AC_MSG_CHECKING([if environ is declared in header files]) +AC_COMPILE_IFELSE([ +AC_LANG_SOURCE([[ +#include <stdlib.h> +#include <unistd.h> +static int +test (void) +{ + const char **env = environ; + return env ? 1 : 0; // this just forces env to be used +} +]]) + ],[ + AC_MSG_RESULT([yes]) + AC_DEFINE([HAVE_ENVIRON_DECL],[1],[environ is declared in headers]) + ],[ + AC_MSG_RESULT([no]) + ] +) + dnl Check for other headers, all optional. AC_CHECK_HEADERS([\ alloca.h \ diff --git a/plugins/sh/call.c b/plugins/sh/call.c index 4ffacfcc..91e69e9a 100644 --- a/plugins/sh/call.c +++ b/plugins/sh/call.c @@ -53,6 +53,10 @@ #include "call.h" +#ifndef HAVE_ENVIRON_DECL +extern char **environ; +#endif + /* Temporary directory for scripts to use. */ char tmpdir[] = "/tmp/nbdkitXXXXXX"; -- 2.25.0
Eric Blake
2020-Apr-28 16:03 UTC
Re: [Libguestfs] [PATCH nbdkit] freebsd, openbsd: Add an extern decl for environ.
On 4/28/20 10:43 AM, Richard W.M. Jones wrote:> --- > configure.ac | 24 ++++++++++++++++++++++++ > plugins/sh/call.c | 4 ++++ > 2 files changed, 28 insertions(+) > > diff --git a/configure.ac b/configure.ac > index cdddae73..9b925539 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -266,6 +266,30 @@ test (int a) > ] > ) > > +dnl 'environ' is not always declared in public header files: > +dnl Linux => <unistd.h> Haiku => <stdlib.h> > +dnl FreeBSD & OpenBSD => not declaredPOSIX says that a user must declare 'environ' themselves (the only POSIX public entry point with that odd requirement); any system that provides it via a header is merely being nice, and should only do so when extensions are requested (but we always request extensions). We could either do this conditionally (as you have done here) or blindly (but then risk collisions if our declaration doesn't quite match the systems that DO provide it via public headers as an extension), so I like your approach. ACK. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Possibly Parallel Threads
- [PATCH nbdkit] server: Add -D nbdkit.environ=1 to dump the environment
- [clang][AST] : extern "C" symbols not present or not visited when traversing TU decl
- [PATCH nbdkit] Add support for socket activation.
- [PATCH mesa 1/3] tgsi: Fix decl.Atomic and .Shared not propagating when parsing tgsi text
- setres[gu]id implicit decl warning on Linux glibc