From: Peter Stephenson <pws@csr.com>
To: "Sean C. Farley" <scf@FreeBSD.org>, zsh-workers@sunsite.dk
Subject: Re: putenv()/environ bug
Date: Tue, 31 Jul 2007 10:00:05 +0100 [thread overview]
Message-ID: <20070731100005.36b8ec20@news01.csr.com> (raw)
In-Reply-To: <20070730173959.B5687@thor.farley.org>
On Mon, 30 Jul 2007 17:44:12 -0500 (CDT)
"Sean C. Farley" <scf@FreeBSD.org> wrote:
> The issue only showed up if zsh was executed again.
>
> Example:
> zsh
> export FOO=BAR
> exec zsh
> unset FOO
> env | grep FOO
> echo $FOO
That's useful, I've added it. I've also made the code a bit more rational
about always using setenv() and unsetenv() in pairs (this shouldn't change
the effect except with a wonky library).
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.120
diff -u -r1.120 exec.c
--- Src/exec.c 30 Jul 2007 20:46:05 -0000 1.120
+++ Src/exec.c 31 Jul 2007 08:57:21 -0000
@@ -529,7 +529,7 @@
* for ARGV0: that's OK since we're about to exec or exit
* on failure.
*/
-#ifdef HAVE_UNSETENV
+#ifdef USE_SET_UNSET_ENV
unsetenv("ARGV0");
#else
delenvvalue(z - 6);
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.134
diff -u -r1.134 params.c
--- Src/params.c 30 Jul 2007 20:46:05 -0000 1.134
+++ Src/params.c 31 Jul 2007 08:57:21 -0000
@@ -610,7 +610,7 @@
createparamtable(void)
{
Param ip, pm;
-#if !defined(HAVE_PUTENV) && !defined(HAVE_SETENV)
+#if !defined(HAVE_PUTENV) && !defined(USE_SET_UNSET_ENV)
char **new_environ;
int envsize;
#endif
@@ -665,7 +665,7 @@
setsparam("LOGNAME", ztrdup((str = getlogin()) && *str ? str : cached_username));
-#if !defined(HAVE_PUTENV) && !defined(HAVE_SETENV)
+#if !defined(HAVE_PUTENV) && !defined(USE_SET_UNSET_ENV)
/* Copy the environment variables we are inheriting to dynamic *
* memory, so we can do mallocs and frees on it. */
envsize = sizeof(char *)*(1 + arrlen(environ));
@@ -3855,7 +3855,7 @@
int
zputenv(char *str)
{
-#ifdef HAVE_SETENV
+#ifdef USE_SET_UNSET_ENV
/*
* If we are using unsetenv() to remove values from the
* environment, which is the safe thing to do, we
@@ -3906,7 +3906,7 @@
}
/**/
-#ifndef HAVE_UNSETENV
+#ifndef USE_SET_UNSET_ENV
/**/
static int
findenv(char *name, int *pos)
@@ -3969,12 +3969,10 @@
addenv(Param pm, char *value)
{
char *newenv = 0;
-#ifndef HAVE_UNSETENV
+#ifndef USE_SET_UNSET_ENV
char *oldenv = 0, *env = 0;
int pos;
-#endif
-#ifndef HAVE_UNSETENV
/*
* First check if there is already an environment
* variable matching string `name'.
@@ -3989,7 +3987,7 @@
pm->env = NULL;
return;
}
-#ifdef HAVE_UNSETENV
+#ifdef USE_SET_UNSET_ENV
/*
* If we are using setenv/unsetenv to manage the environment,
* we simply store the string we created in pm->env since
@@ -4052,7 +4050,7 @@
* string. */
-#ifndef HAVE_UNSETENV
+#ifndef USE_SET_UNSET_ENV
/**/
void
delenvvalue(char *x)
@@ -4078,7 +4076,7 @@
void
delenv(Param pm)
{
-#ifdef HAVE_UNSETENV
+#ifdef USE_SET_UNSET_ENV
unsetenv(pm->node.nam);
zsfree(pm->env);
#else
Index: Src/system.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/system.h,v
retrieving revision 1.45
diff -u -r1.45 system.h
--- Src/system.h 30 Jul 2007 20:46:05 -0000 1.45
+++ Src/system.h 31 Jul 2007 08:57:22 -0000
@@ -697,8 +697,8 @@
* We always need setenv and unsetenv in pairs, because
* we don't know how to do memory management on the values set.
*/
-#ifndef HAVE_UNSETENV
-#undef HAVE_SETENV
+#if defined(HAVE_SETENV) && defined(HAVE_UNSETENV)
+# define USE_SET_UNSET_ENV
#endif
Index: Test/B02typeset.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/B02typeset.ztst,v
retrieving revision 1.14
diff -u -r1.14 B02typeset.ztst
--- Test/B02typeset.ztst 30 Jul 2007 20:55:41 -0000 1.14
+++ Test/B02typeset.ztst 31 Jul 2007 08:57:22 -0000
@@ -381,10 +381,27 @@
export ENVFOO=bar
print ENVFOO in environment
env | grep '^ENVFOO'
+ print Changing ENVFOO
+ ENVFOO="not bar any more"
+ env | grep '^ENVFOO'
unset ENVFOO
print ENVFOO no longer in environment
env | grep '^ENVFOO'
1:Adding and removing values to and from the environment
>ENVFOO in environment
>ENVFOO=bar
+>Changing ENVFOO
+>ENVFOO=not bar any more
>ENVFOO no longer in environment
+
+ (export FOOENV=BAR
+ env | grep '^FOOENV'
+ print Exec
+ exec $ZTST_testdir/../Src/zsh -c '
+ print Unset
+ unset FOOENV
+ env | grep "^FOOENV"')
+1:Can unset environment variables after exec
+>FOOENV=BAR
+>Exec
+>Unset
.
next prev parent reply other threads:[~2007-07-31 9:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-25 15:09 Sean C. Farley
2007-07-25 20:53 ` Peter Stephenson
2007-07-26 0:14 ` Sean C. Farley
2007-07-28 18:46 ` Andrey Borzenkov
2007-07-29 19:08 ` Sean C. Farley
2007-07-30 20:39 ` Peter Stephenson
2007-07-30 20:52 ` Peter Stephenson
2007-07-30 22:44 ` Sean C. Farley
2007-07-31 9:00 ` Peter Stephenson [this message]
2007-07-31 18:09 ` Sean C. Farley
2007-07-30 22:39 ` Sean C. Farley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070731100005.36b8ec20@news01.csr.com \
--to=pws@csr.com \
--cc=scf@FreeBSD.org \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).