From owner-freebsd-current@FreeBSD.ORG Sat Jul 14 15:25:21 2007 Return-Path: X-Original-To: freebsd-current@FreeBSD.org Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B213F16A403 for ; Sat, 14 Jul 2007 15:25:21 +0000 (UTC) (envelope-from scf@FreeBSD.org) Received: from mail.farley.org (farley.org [67.64.95.201]) by mx1.freebsd.org (Postfix) with ESMTP id 7374213C441 for ; Sat, 14 Jul 2007 15:25:21 +0000 (UTC) (envelope-from scf@FreeBSD.org) Received: from thor.farley.org (thor.farley.org [192.168.1.5]) by mail.farley.org (8.14.1/8.14.1) with ESMTP id l6EFRBjC072535; Sat, 14 Jul 2007 10:27:11 -0500 (CDT) (envelope-from scf@FreeBSD.org) Date: Sat, 14 Jul 2007 10:25:03 -0500 (CDT) From: "Sean C. Farley" To: Andrey Chernov In-Reply-To: <20070714022638.GA25256@nagual.pp.ru> Message-ID: <20070714080553.I27236@thor.farley.org> References: <20070713162742.GA16260@nagual.pp.ru> <20070713142545.K26096@thor.farley.org> <20070713202433.GA19856@nagual.pp.ru> <20070713203915.GA20270@nagual.pp.ru> <20070713171942.Q26096@thor.farley.org> <20070713224608.GB21695@nagual.pp.ru> <20070713184543.A26096@thor.farley.org> <20070714004116.GA22909@nagual.pp.ru> <20070713200048.X26971@thor.farley.org> <20070714014319.GA24701@nagual.pp.ru> <20070714022638.GA25256@nagual.pp.ru> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.1 X-Spam-Checker-Version: SpamAssassin 3.2.1 (2007-05-02) on mail.farley.org Cc: freebsd-current Subject: Re: Environment handling broken in /bin/sh with changes to t,set,put}env() X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Jul 2007 15:25:21 -0000 On Sat, 14 Jul 2007, Andrey Chernov wrote: *snip* > BTW, I fear about another place on this matter, merge_environ(). > Look at this example: > > ... some setenv's called before > > nenv[0] = NULL; > environ = nenv; > unsetenv("NONEXISTEN"); > > What happens to environ pointer _after_ that? > > unsetenv() leads to environ = watchEnviron; in the merge_environ() but > this environ is never rebuilded because no single setenv() is called > from merge_environ() and no rebuild_environ() is called from > unsetenv() due to "NONEXISTENT" value not found. It means reassigned > environ inherits stale pointers from non-rebuilded watchEnviron which > not equals to environ[0] == NULL > > Did I miss something? No. I see it too. Here are the changes: 1. __merge_environ no longer touches environ. Only __rebuild_environ(), __build_env() and __clean_env() alter environ. 2. watchEnviron renamed to intEnviron. 3. __rebuild_environ() uses intEnviron when cycling through the environment; it only sets environ. This way environ is not changed unless it has at least one name-value pair. The new patch is here: http://www.farley.org/freebsd/tmp/setenv/clearenv/patch2 Sean -- scf@FreeBSD.org