environ variable from C runtime is not declared on all systems

This commit is contained in:
Gerhard Rieger 2015-04-02 17:29:40 +02:00
parent 1f0fc69d60
commit 0ccd377a31
5 changed files with 38 additions and 0 deletions

View file

@ -331,6 +331,8 @@ porting:
including <linux/errqueue.h> and a weakness in the conditional code. including <linux/errqueue.h> and a weakness in the conditional code.
Thanks to Michel Normand for reporting this issue. Thanks to Michel Normand for reporting this issue.
Use 'environ' variable only when provided by runtime
new features: new features:
added option max-children that limits the number of concurrent child added option max-children that limits the number of concurrent child
processes. Thanks to Sam Liddicott for providing the patch. processes. Thanks to Sam Liddicott for providing the patch.

View file

@ -5,6 +5,10 @@
#ifndef __compat_h_included #ifndef __compat_h_included
#define __compat_h_included 1 #define __compat_h_included 1
#if !HAVE_DECL_ENVIRON && HAVE_VAR_ENVIRON
extern char **environ;
#endif
/*****************************************************************************/ /*****************************************************************************/
/* I dont like this system dependent part, but it would be quite a challenge /* I dont like this system dependent part, but it would be quite a challenge
for configure */ for configure */

View file

@ -53,6 +53,13 @@
/* Define if you have the putenv function. */ /* Define if you have the putenv function. */
#undef HAVE_PUTENV #undef HAVE_PUTENV
/* Define if your cc provides char **environ declaration.
This implies HAVE_VAR_ENVIRON */
#undef HAVE_DECL_ENVIRON
/* Define if you have the char **environ variable */
#undef HAVE_VAR_ENVIRON
/* Define if you have the select function. */ /* Define if you have the select function. */
#undef HAVE_SELECT #undef HAVE_SELECT

View file

@ -1916,6 +1916,29 @@ if test -n "$WITH_FIPS"; then
fi fi
AC_SUBST(FIPSLD_CC) AC_SUBST(FIPSLD_CC)
# autoconf does not seem to provide AC_CHECK_VAR or so
# thus we have to check by foot
AC_MSG_CHECKING(for declaration of environ)
AC_CACHE_VAL(sc_cv_decl_environ,
[AC_TRY_COMPILE([#include <unistd.h>],[char **s = environ;],
[sc_cv_decl_environ=yes],
[sc_cv_decl_environ=no])])
if test $sc_cv_decl_environ = yes; then
AC_DEFINE(HAVE_DECL_ENVIRON)
fi
AC_MSG_RESULT($sc_cv_decl_environ)
# on some systems environ exists but not the declaration
AC_MSG_CHECKING(for var environ)
AC_CACHE_VAL(sc_cv_var_environ,
[AC_TRY_COMPILE([],[extern char **environ; char **s = environ;],
[sc_cv_var_environ=yes],
[sc_cv_var_environ=no])])
if test $sc_cv_var_environ = yes; then
AC_DEFINE(HAVE_VAR_ENVIRON)
fi
AC_MSG_RESULT($sc_cv_var_environ)
# allow BUILD_DATE to be externally set for build reproducibility # allow BUILD_DATE to be externally set for build reproducibility
if test "$BUILD_DATE"; then if test "$BUILD_DATE"; then
AC_DEFINE_UNQUOTED(BUILD_DATE, ["$BUILD_DATE"]) AC_DEFINE_UNQUOTED(BUILD_DATE, ["$BUILD_DATE"])

View file

@ -1288,6 +1288,7 @@ static int openssl_delete_cert_info(void) {
for (i = 0; i < l; ++i) envprefix[i] = toupper(envprefix[i]); for (i = 0; i < l; ++i) envprefix[i] = toupper(envprefix[i]);
strncat(envprefix+l, "_OPENSSL_", XIO_ENVNAMELEN-l-1); strncat(envprefix+l, "_OPENSSL_", XIO_ENVNAMELEN-l-1);
#if HAVE_VAR_ENVIRON
entry = (const char **)environ; entry = (const char **)environ;
while (*entry != NULL) { while (*entry != NULL) {
if (!strncmp(*entry, envprefix, strlen(envprefix))) { if (!strncmp(*entry, envprefix, strlen(envprefix))) {
@ -1299,6 +1300,7 @@ static int openssl_delete_cert_info(void) {
++entry; ++entry;
} }
} }
#endif /* HAVE_VAR_ENVIRON */
return 0; return 0;
} }