From owner-freebsd-ports@FreeBSD.ORG Sun May 26 17:55:14 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 67F48312 for ; Sun, 26 May 2013 17:55:14 +0000 (UTC) (envelope-from shoesoft@gmx.net) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by mx1.freebsd.org (Postfix) with ESMTP id 08E8260C for ; Sun, 26 May 2013 17:55:13 +0000 (UTC) Received: from mailout-de.gmx.net ([10.1.76.16]) by mrigmx.server.lan (mrigmx001) with ESMTP (Nemesis) id 0LmQuq-1U73UY1OXi-00ZucN for ; Sun, 26 May 2013 19:55:04 +0200 Received: (qmail invoked by alias); 26 May 2013 17:55:04 -0000 Received: from h081217076060.dyn.cm.kabsi.at (EHLO walrus.pepperland) [81.217.76.60] by mail.gmx.net (mp016) with SMTP; 26 May 2013 19:55:04 +0200 X-Authenticated: #16703784 X-Provags-ID: V01U2FsdGVkX1+EdXUjt1iE5TY5OOB3OciDJJyA3jWsGWJyAJxXH1 Fqu99/xxPn5z6g Message-ID: <51A24C77.6000108@gmx.net> Date: Sun, 26 May 2013 19:55:03 +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> In-Reply-To: <20130526172015.GA1334@albert.catwhisker.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit 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: Sun, 26 May 2013 17:55:14 -0000 On 05/26/2013 19:20, David Wolfskill wrote: > A while back, I volunteered to maintain x11-wm/piewm, as it had been > assigned to "ports" and I'm one of the very few folks I know who uses > it. ... > So I hacked twm.c, per: > > --- twm.c 1998-06-12 13:28:07.000000000 -0700 > +++ twm.c 2013-05-10 21:02:32.000000000 -0700 > @@ -93,6 +93,7 @@ > #endif > > #include > +#include > #include > #include > #include "twm.h" > @@ -177,6 +178,8 @@ > > unsigned long black, white; > > +extern char **environ; > + > /*********************************************************************** > * > * Procedure: > @@ -186,7 +189,7 @@ > */ > > int > -main(int argc, char **argv, char **environ) > +main(int argc, char **argv) > { > Window root, parent, *children; > unsigned int nchildren; > > > rebuilt piewm, et voilą: no crash. :-) > > I thought this was encouraging, and sent a note to Russ Nelson at > crynwr.com -- the upstream site. That was on 10 May; I've had no > response. > > I subsequently rebuild piewm with the patch applied for my usual > FreeBSD/i386 environment, and it's (also) been trouble-free. (That > said, I don't actually do anything with the environment for piewm. > Indeed, in nearly all respects, I could use tvtwm without any difference > -- and those that would show up are too arcane to describe here.) > > So I have a couple of questions related to the above: > * Is the patch correct? I don't do much with C, and even less with C > code that accesses the environment. (When I write code, it's normally > scripts, mostly in /bin/sh.) getenv(3) mentioned the "#include > ", so I did that based on theat man page. I didn't see > anything about declaring environ as an "extern char **", but wasn't > keen on making more changes than necessary to the code. (Mind, I > fully support making "necessary" -- or even "strongly advised" -- > changes.) Should be fine. See environ(7) or http://pubs.opengroup.org/onlinepubs/9699919799/functions/environ.html: "In addition, the following variable, which must be declared by the user if it is to be used directly: extern char **environ; " Including is not necessary to access the environ variable. -- Stefan