delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/05/31/09:43:46

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=sy61xnd8W4M9Yx9f
ewoQDUq0gIB5EiSJL8odvu6+T+yH7gH5YL5iXO4N/DCUeHeqfgwspHgml20VXEZF
Py+x0T7ItZVJuwoAUbyV48cl5s88ZneyC41w8DfiKn0ZUiBTiubEEKzQFbYZAcj9
tVVXpAFIN3AE5ziyU3fgRVPFfrI=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=MTVN9pNcaMuULZGy5c6fUG
UBwkY=; b=k43YPAvXeWTCuWUx0O0Dd0vAVimx/xCIav2zvlOpW+QpKEi6cG2kw4
vEwEITC8T4v2yiz19QbW5D8yfUOsLUgnZGRg3QG1Ywi6io30j+5Ak3Vdg5ch65cZ
Ap2eFw9bx/w0QJ096UDwqBn3cQAUh/gpFK+U2s75NdhHkiv4OYQz8=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Principal, xsi, virtualization, Virtualization
X-HELO: mx1.redhat.com
Subject: Re: Help with C clearenv and setenv
To: cygwin AT cygwin DOT com, sam DOT habiel AT gmail DOT com
References: <CABHT962nB5jK2sNP9jGaVEbWGrvD72hBVN_q6xX9TKuq3yQ0Gg AT mail DOT gmail DOT com>
From: Eric Blake <eblake AT redhat DOT com>
Message-ID: <7df53a72-cf45-a5df-45dd-6ea2b7d8e0ed@redhat.com>
Date: Thu, 31 May 2018 08:43:30 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0
MIME-Version: 1.0
In-Reply-To: <CABHT962nB5jK2sNP9jGaVEbWGrvD72hBVN_q6xX9TKuq3yQ0Gg@mail.gmail.com>
X-IsSubscribed: yes

On 05/30/2018 09:48 AM, Sam Habiel wrote:
> I have code for a database I am porting to Cygwin.
> 
> Part of that code is a clearenv() then a couple of setenvs. There is
> an ifdef for Cygwin, as it doesn't implement clearenv.

It wouldn't be hard to implement clearenv() for a future release of 
Cygwin, at least for a version that leaves environ pointing to a 
1-element array containing NULL.  A bit more effort and we could 
probably also support glibc's notion of environ==NULL being shorthand 
for an empty environment; in fact, POSIX states:

"After assigning a new value to environ, applications should not rely on 
the new environment strings remaining part of the environment, as a call 
to getenv(), [XSI] [Option Start] putenv(), [Option End] setenv(), 
unsetenv(), or any function that is dependent on an environment variable 
may, on noticing that environ has changed, copy the environment strings 
to a new array and assign environ to point to it."

where we could check for environ==NULL on entry to any of those 
functions as one of the times that we reassign environ back to a 
non-NULL array with one NULL entry.

Note, however, that POSIX says that it is not portable to exec processes 
with a completely empty environment.  In particular, Cygwin is rather 
fragile if some things like PATH are not defined in the environment. 
Having a temporarily empty environ may work if you then add back enough 
state before Cygwin has to look something up from the environment.  The 
POSIX recommendation is that you should always have at least the 
equivalent of:

env -i $(getconf V7_ENV) PATH="$(getconf PATH)" command

in your environment, at least when exec'ing processes.

> It just sets
> environ = NULL. Well--that really breaks setenv! It returns a "Bad
> Poniter" error (-1).

What it SHOULD do is set environ to a one-element array containing NULL, 
at least until someone submits a patch adding the glibc extension of 
clearenv() to Cygwin.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019