From: Alan Burlison Date: Tue, 11 Oct 2005 16:29:54 +0000 (+0100) Subject: environ fixup X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=88f5bc07adcbdcc8427eef58d88a43884ef3f99a;p=p5sagit%2Fp5-mst-13.2.git environ fixup Message-ID: <434BDA72.4090109@sun.com> p4raw-id: //depot/perl@25737 --- diff --git a/handy.h b/handy.h index e28faa8..69ee8d3 100644 --- a/handy.h +++ b/handy.h @@ -175,7 +175,7 @@ typedef U64TYPE U64; #endif /* HMB H.Merijn Brand - a placeholder for preparing Configure patches */ -#if defined(HAS_MALLOC_SIZE) && defined(HAS_MALLOC_GOOD_SIZE) && defined(HAS_UNSETENV) +#if defined(HAS_MALLOC_SIZE) && defined(HAS_MALLOC_GOOD_SIZE) /* Not (yet) used at top level, but mention them for metaconfig */ #endif diff --git a/hints/solaris_2.sh b/hints/solaris_2.sh index a322ac0..a06d9e8 100644 --- a/hints/solaris_2.sh +++ b/hints/solaris_2.sh @@ -612,4 +612,19 @@ EOM esac EOCBU +# +# If unsetenv is available, use it in conjunction with PERL_USE_SAFE_PUTENV to +# work around Sun bugid 6333830. Both unsetenv and 6333830 only appear in +# Solaris 10, so we don't need to probe explicitly for an OS version. We have +# to append this test to the end of config.over as it needs to run after +# Configure has probed for unsetenv, and this hints file is processed before +# that has happened. +# +cat >> config.over <<'EOOVER' +if test "$d_unsetenv" = "$define" -a \ + `expr "$ccflags" : '.*-D_PERL_USE_SAFE_PUTENV'` -eq 0; then + ccflags="$ccflags -DPERL_USE_SAFE_PUTENV" +fi +EOOVER + rm -f try.c try.o try a.out diff --git a/perl.c b/perl.c index bc1f652..72289a2 100644 --- a/perl.c +++ b/perl.c @@ -4592,7 +4592,16 @@ S_init_perllib(pTHX) if (!PL_tainting) { #ifndef VMS s = PerlEnv_getenv("PERL5LIB"); +/* + * It isn't possible to delete an environment variable with + * PERL_USE_SAFE_PUTENV set unless setenv() is also available, so in that case + * we treat PERL5LIB as undefined if it has a zero-length value. + */ +#if defined(PERL_USE_SAFE_PUTENV) && ! defined(HAS_UNSETENV) + if (s && *s != '\0') +#else if (s) +#endif incpush(s, TRUE, TRUE, TRUE, FALSE); else incpush(PerlEnv_getenv("PERLLIB"), FALSE, FALSE, TRUE, FALSE); diff --git a/util.c b/util.c index ccbb7f9..8fa774f 100644 --- a/util.c +++ b/util.c @@ -1496,19 +1496,39 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val) } else { # endif # if defined(__CYGWIN__) || defined(EPOC) || defined(SYMBIAN) - setenv(nam, val, 1); +# if defined(HAS_UNSETENV) + if (val == NULL) { + (void)unsetenv(nam); + } else { + (void)setenv(nam, val, 1); + } +# else /* ! HAS_UNSETENV */ + (void)setenv(nam, val, 1); +# endif /* HAS_UNSETENV */ # else - char *new_env; - const int nlen = strlen(nam); - int vlen; - if (!val) { - val = ""; - } - vlen = strlen(val); - new_env = (char*)safesysmalloc((nlen + vlen + 2) * sizeof(char)); - /* all that work just for this */ - my_setenv_format(new_env, nam, nlen, val, vlen); - (void)putenv(new_env); +# if defined(HAS_UNSETENV) + if (val == NULL) { + (void)unsetenv(nam); + } else { + int nlen = strlen(nam); + int vlen = strlen(val); + char *new_env = + (char*)safesysmalloc((nlen + vlen + 2) * sizeof(char)); + my_setenv_format(new_env, nam, nlen, val, vlen); + (void)putenv(new_env); + } +# else /* ! HAS_UNSETENV */ + char *new_env; + int nlen = strlen(nam), vlen; + if (!val) { + val = ""; + } + vlen = strlen(val); + new_env = (char*)safesysmalloc((nlen + vlen + 2) * sizeof(char)); + /* all that work just for this */ + my_setenv_format(new_env, nam, nlen, val, vlen); + (void)putenv(new_env); +# endif /* HAS_UNSETENV */ # endif /* __CYGWIN__ */ #ifndef PERL_USE_SAFE_PUTENV }