Change 16348 by gsar@onru on 2002/05/02 15:44:48
manual integrate of change#16332 from maint-5.6 branch
Affected files ...
.... //depot/perl/mg.c#232 edit
.... //depot/perl/perl.c#435 edit
.... //depot/perl/sv.c#544 edit
.... //depot/perl/util.c#345 edit
Differences ...
==== //depot/perl/mg.c#232 (text) ====
Index: perl/mg.c
--- perl/mg.c.~1~ Thu May 2 10:00:05 2002
+++ perl/mg.c Thu May 2 10:00:05 2002
@@ -990,11 +990,16 @@
#if defined(VMS) || defined(EPOC)
Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system");
#else
-# if defined(PERL_IMPLICIT_SYS) || defined(WIN32)
+# if defined(PERL_IMPLICIT_SYS) || defined(WIN32)
PerlEnv_clearenv();
-# else
-# ifdef USE_ENVIRON_ARRAY
-# ifndef PERL_USE_SAFE_PUTENV
+# else
+# ifdef USE_ENVIRON_ARRAY
+# 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)
@@ -1002,11 +1007,11 @@
else
for (i = 0; environ[i]; i++)
safesysfree(environ[i]);
-# endif /* PERL_USE_SAFE_PUTENV */
+# endif /* PERL_USE_SAFE_PUTENV */
environ[0] = Nullch;
-
-# endif /* USE_ENVIRON_ARRAY */
+ }
+# endif /* USE_ENVIRON_ARRAY */
# endif /* PERL_IMPLICIT_SYS || WIN32 */
#endif /* VMS || EPC */
return 0;
@@ -2239,7 +2244,12 @@
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))
+ {
my_setenv("NoNe SuCh", Nullch);
/* force copy of environment */
for (i = 0; PL_origenviron[i]; i++)
==== //depot/perl/perl.c#435 (text) ====
Index: perl/perl.c
--- perl/perl.c.~1~ Thu May 2 10:00:05 2002
+++ perl/perl.c Thu May 2 10:00:05 2002
@@ -498,7 +498,13 @@
* so we certainly shouldn't free it here
*/
#if defined(USE_ENVIRON_ARRAY) && !defined(PERL_USE_SAFE_PUTENV)
- 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++)
@@ -3576,8 +3582,14 @@
*/
if (!env)
env = environ;
- if (env != environ)
+ if (env != environ
+# ifdef USE_ITHREADS
+ && PL_curinterp == aTHX
+# endif
+ )
+ {
environ[0] = Nullch;
+ }
if (env)
for (; *env; env++) {
if (!(s = strchr(*env,'=')))
==== //depot/perl/sv.c#544 (text) ====
Index: perl/sv.c
--- perl/sv.c.~1~ Thu May 2 10:00:05 2002
+++ perl/sv.c Thu May 2 10:00:05 2002
@@ -6594,8 +6594,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/perl/util.c#345 (text) ====
Index: perl/util.c
--- perl/util.c.~1~ Thu May 2 10:00:05 2002
+++ perl/util.c Thu May 2 10:00:05 2002
@@ -1594,6 +1594,11 @@
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? */
@@ -1652,6 +1657,7 @@
(void)putenv(new_env);
# endif /* __CYGWIN__ */
#endif /* PERL_USE_SAFE_PUTENV */
+ }
}
#else /* WIN32 || NETWARE */
End of Patch.