From owner-freebsd-ports@FreeBSD.ORG Mon May 27 16:33:26 2013 Return-Path: Delivered-To: freebsd-ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 7C0B3643 for ; Mon, 27 May 2013 16:33:26 +0000 (UTC) (envelope-from shoesoft@gmx.net) Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by mx1.freebsd.org (Postfix) with ESMTP id 02A1BD7B for ; Mon, 27 May 2013 16:33:25 +0000 (UTC) Received: from mailout-de.gmx.net ([10.1.76.34]) by mrigmx.server.lan (mrigmx001) with ESMTP (Nemesis) id 0Lex3B-1U5n4V05JH-00qkKC for ; Mon, 27 May 2013 18:33:16 +0200 Received: (qmail invoked by alias); 27 May 2013 16:33:15 -0000 Received: from h081217076060.dyn.cm.kabsi.at (EHLO walrus.pepperland) [81.217.76.60] by mail.gmx.net (mp034) with SMTP; 27 May 2013 18:33:15 +0200 X-Authenticated: #16703784 X-Provags-ID: V01U2FsdGVkX1+xku8uZl2xvl4iHmOYKlaQ8Qyrfr6h+StDtUKcwc ScoWmNiky6gWle Message-ID: <51A38ACB.8060008@gmx.net> Date: Mon, 27 May 2013 18:33:15 +0200 From: Stefan Ehmann User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130518 Thunderbird/17.0.6 MIME-Version: 1.0 To: freebsd-ports@freebsd.org Subject: Re: Proper way to access executable's "environment"? References: <20130526172015.GA1334@albert.catwhisker.org> <20130527054313.372869c1@X220.ovitrap.com> <20130527133259.GF1334@albert.catwhisker.org> In-Reply-To: <20130527133259.GF1334@albert.catwhisker.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 May 2013 16:33:26 -0000 On 05/27/2013 15:32, David Wolfskill wrote: > On Mon, May 27, 2013 at 05:43:13AM +0700, Erich Dollansky wrote: >> ... >>> piewm's twm.c declares main as: >>> >>> int >>> main(int argc, char **argv, char **environ) >>> { >> >> I use this concept since decades but with different names. Could it be >> a problem of overlapping names? >> ... > > It was pointed out to me that -- other than assigning "Environ = > environ" -- the code in piewm's twm.c didn't actually use the values of > environ or Environ. [Thanks, Stefan!] > > Elsewhere, there is a putenv() implementation for environments that > lack it, and the code uses getenv(), as well. > > Doing a few more comparisons with twm.c from tvtwm and from twm itself; > I have a few more observations: > > * tvtwm's twm.c is more recent than that of piewm: > - * $XConsortium: twm.c,v 1.124 91/05/08 11:01:54 dave Exp $ > + * $XConsortium: twm.c,v 1.111 90/03/23 13:23:34 jim Exp $ > > * twm's twm.c has a copyright block dated 2005 from Hitachi, Ltd. > > * Merely inserting the "#include " in piewm's twm.c appears > to be a minimal effective change: Once that's done, the SIGSEGV goes > away. > > * Neither tvtwm's nor twm's twm.c has the "#include " (and > neither gets a SIGSEGV). > > * As Stefan pointed out, I was able to completely remove the references > to both "environ" and "Environ" from piewm's twm.c; the result builds > and runs without problem. > > * tvtwm's twm.c has these environ and Environ variables (and, as above, > lacks the "#include " and doesn't get the SIGSEGV). > > * twm's twm.c lacks the environ and Environ variables (and main() is > defined as a function that takes but 2 arguments). > > I suspect that I'm failing to understand at least part of what's causing > the actual problem in piewm. The environ variable had nothing to do with the segfault. The third argument to main() is supported historically, but it's not standardized. Using the extern declaration is more portable. But apparently the main argument just works fine in FreeBSD. Thomas explained why getenv() causes a segfault when is not included. This is the actual problem that needs to be fixed. twm.c indirectly includes via twm.h. So that's why tvtwm and twm work fine. IOW, just including should be the right fix. Hope all mysteries are solved now :) -- Stefan