From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25483 invoked from network); 31 Jul 2007 09:02:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.1 (2007-05-02) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.1 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 31 Jul 2007 09:02:10 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 39681 invoked from network); 31 Jul 2007 09:02:03 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 31 Jul 2007 09:02:03 -0000 Received: (qmail 18377 invoked by alias); 31 Jul 2007 09:02:00 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23730 Received: (qmail 18362 invoked from network); 31 Jul 2007 09:01:59 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 31 Jul 2007 09:01:59 -0000 Received: (qmail 39325 invoked from network); 31 Jul 2007 09:01:59 -0000 Received: from cluster-g.mailcontrol.com (85.115.41.190) by a.mx.sunsite.dk with SMTP; 31 Jul 2007 09:01:55 -0000 Received: from rly07g.srv.mailcontrol.com (localhost.localdomain [127.0.0.1]) by rly07g.srv.mailcontrol.com (MailControl) with ESMTP id l6V91Od8008258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 31 Jul 2007 10:01:44 +0100 Received: from submission.mailcontrol.com (submission.mailcontrol.com [86.111.216.190]) by rly07g.srv.mailcontrol.com (MailControl) id l6V90UO3004375 for zsh-workers@sunsite.dk; Tue, 31 Jul 2007 10:00:30 +0100 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly07g-eth0.srv.mailcontrol.com (envelope-sender Peter.Stephenson@csr.com) (MIMEDefang) with ESMTP id l6V8wNW1030773; Tue, 31 Jul 2007 10:00:30 +0100 (BST) Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Tue, 31 Jul 2007 10:00:05 +0100 Date: Tue, 31 Jul 2007 10:00:05 +0100 From: Peter Stephenson To: "Sean C. Farley" , zsh-workers@sunsite.dk Subject: Re: putenv()/environ bug Message-ID: <20070731100005.36b8ec20@news01.csr.com> In-Reply-To: <20070730173959.B5687@thor.farley.org> References: <20070725093254.T20275@thor.farley.org> <20070725215321.00e3b110.p.w.stephenson@ntlworld.com> <20070725184302.S23862@thor.farley.org> <200707282246.16663.arvidjaar@newmail.ru> <20070729140248.D2588@thor.farley.org> <20070730213934.aefff281.p.w.stephenson@ntlworld.com> <20070730215232.ff040a3f.p.w.stephenson@ntlworld.com> <20070730173959.B5687@thor.farley.org> Organization: CSR X-Mailer: Claws Mail 2.9.1 (GTK+ 2.10.13; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 31 Jul 2007 09:00:05.0921 (UTC) FILETIME=[30486110:01C7D351] X-Scanned-By: MailControl A-07-08-00 (www.mailcontrol.com) on 10.71.1.117 On Mon, 30 Jul 2007 17:44:12 -0500 (CDT) "Sean C. Farley" 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 .