Change 16332 by gsar@onru on 2002/05/02 06:49:17
isolate all environ diddling to the initial interpreter; any
additional interpreters created after the first one cannot
propagate %ENV changes down to the real environment; this
should fix %ENV related races (e.g. multiple threads attempting
to free() environ entries when they run C<%ENV = ()>)
Affected files ...
.... //depot/maint-5.6/perl/mg.c#27 edit
.... //depot/maint-5.6/perl/perl.c#52 edit
.... //depot/maint-5.6/perl/sv.c#64 edit
.... //depot/maint-5.6/perl/util.c#41 edit
Differences ...
==== //depot/maint-5.6/perl/mg.c#27 (text) ====
Index: perl/mg.c
--- perl/mg.c.~1~ Thu May 2 01:00:06 2002
+++ perl/mg.c Thu May 2 01:00:06 2002
@@ -906,7 +906,12 @@
PerlEnv_clearenv();
# else
#if !defined(MACOS_TRADITIONAL)
-# ifndef PERL_USE_SAFE_PUTENV
+# if defined(USE_ITHREADS)
+ /* only the parent thread can clobber the process environment */
+ if (PL_curinterp == aTHX)
+# endif
+ {
+# ifndef PERL_USE_SAFE_PUTENV
I32 i;
if (environ == PL_origenviron)
@@ -914,10 +919,10 @@
else
for (i = 0; environ[i]; i++)
safesysfree(environ[i]);
-# endif /* PERL_USE_SAFE_PUTENV */
+# endif /* PERL_USE_SAFE_PUTENV */
environ[0] = Nullch;
-
+ }
#endif /* !defined(MACOS_TRADITIONAL) */
# endif /* PERL_IMPLICIT_SYS */
#endif /* VMS */
@@ -2023,9 +2028,13 @@
break;
}
/* can grab env area too? */
- if (PL_origenviron && (PL_origenviron[0] == s + 1
+ if (PL_origenviron
+#ifdef USE_ITHREADS
+ && PL_curinterp == aTHX
+#endif
+ && (PL_origenviron[0] == s + 1
#ifdef OS2
- || (PL_origenviron[0] == s + 9 && (s += 8))
+ || (PL_origenviron[0] == s + 9 && (s += 8))
#endif
)) {
my_setenv("NoNe SuCh", Nullch);
==== //depot/maint-5.6/perl/perl.c#52 (text) ====
Index: perl/perl.c
--- perl/perl.c.~1~ Thu May 2 01:00:06 2002
+++ perl/perl.c Thu May 2 01:00:06 2002
@@ -440,7 +440,13 @@
/* jettison our possibly duplicated environment */
#ifdef USE_ENVIRON_ARRAY
- if (environ != PL_origenviron) {
+ if (environ != PL_origenviron
+#ifdef USE_ITHREADS
+ /* only main thread can free environ[0] contents */
+ && PL_curinterp == aTHX
+#endif
+ )
+ {
I32 i;
for (i = 0; environ[i]; i++)
@@ -3329,8 +3335,14 @@
*/
if (!env)
env = environ;
- if (env != environ)
+ if (env != environ
+# ifdef USE_ITHREADS
+ && PL_curinterp == aTHX
+# endif
+ )
+ {
environ[0] = Nullch;
+ }
#ifdef NEED_ENVIRON_DUP_FOR_MODIFY
{
char **env_base;
==== //depot/maint-5.6/perl/sv.c#64 (text) ====
Index: perl/sv.c
--- perl/sv.c.~1~ Thu May 2 01:00:06 2002
+++ perl/sv.c Thu May 2 01:00:06 2002
@@ -5109,8 +5109,14 @@
if (GvHV(gv) && !HvNAME(GvHV(gv))) {
hv_clear(GvHV(gv));
#ifdef USE_ENVIRON_ARRAY
- if (gv == PL_envgv)
+ if (gv == PL_envgv
+# ifdef USE_ITHREADS
+ && PL_curinterp == aTHX
+# endif
+ )
+ {
environ[0] = Nullch;
+ }
#endif
}
}
==== //depot/maint-5.6/perl/util.c#41 (text) ====
Index: perl/util.c
--- perl/util.c.~1~ Thu May 2 01:00:06 2002
+++ perl/util.c Thu May 2 01:00:06 2002
@@ -1982,9 +1982,16 @@
void
Perl_my_setenv(pTHX_ char *nam, char *val)
{
+#ifdef USE_ITHREADS
+ /* only parent thread can modify process environment */
+ if (PL_curinterp == aTHX)
+#endif
+ {
#ifndef PERL_USE_SAFE_PUTENV
/* most putenv()s leak, so we manipulate environ directly */
- register I32 i=setenv_getix(nam); /* where does it go? */
+ register I32 i;
+
+ i = setenv_getix(nam); /* where does it go? */
if (environ == PL_origenviron) { /* need we copy environment? */
I32 j;
@@ -2030,6 +2037,7 @@
(void)putenv(new_env);
# endif /* __CYGWIN__ */
#endif /* PERL_USE_SAFE_PUTENV */
+ }
}
#else /* WIN32 */
End of Patch.