www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/06/14/14:30:29

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 55EIUTF02474160
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 55EIUTF02474160
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=f/5S5rS+
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 168B038F941F
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1749925827;
bh=OBK4KeB9LQeQNSTZHe0m0PbiXOZUmRoO+wXzxRzFARI=;
h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
From;
b=f/5S5rS+8XvI654PSoNqbDzfc6k/uPDhbkvVnR3phfGiP+VbAgj64v+e9Ark3wsAe
B/zKD6NOwXxvSl6XB5ITFZsOviXoA38fgBSDpJD7A5h1KbZc4l//u5jU9DRyP215xh
nerxlI4fsMUn+78XNsB4VkipJnbFkW7P1BEoGSJY=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A19D13871884
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A19D13871884
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749925800; cv=none;
b=mfqEO/4a9KlcESSEci/V+1GPzKQpAH3yfQ58qqsMoExpF9ioij5nExzC6bzU5vrGJotkB0KnevHm0qpTe4/d/qA1TySZFZurZZLpI5e8HY5Tg+4oyMN9qZuXDYE4fOEWjFCLGeCKUbmWLfZg+4elpyfiaQt1EXsVtnqNG7yWwuk=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1749925800; c=relaxed/simple;
bh=+Xof+1xhXwIM0dOy2SFh9I+N62nb/G+604IbvoULuTk=;
h=Message-ID:Date:MIME-Version:From:Subject:To:DKIM-Signature;
b=QVxjahX/lHdj1DHANBiY5fEpd+FnP4zITzX3oQmgYG3a4om+9PeafVYlzL/gZ7nZa361L9SrY3efnYG2cP6YmWPOYcaR7XFPLAc4zcslgvmo/ZCNZWv9NvKcwEcE5aRBLv6WyCiPsd8717O347pj26ryXm2kjcfZ3VRo42zVYXo=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A19D13871884
Message-ID: <11206d22-8533-42d8-afd5-cd1b2056cb59@SystematicSW.ab.ca>
Date: Sat, 14 Jun 2025 12:29:57 -0600
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: posix_spawn difference from Linux
To: cygwin AT cygwin DOT com
References: <35d5a3b2-e060-cb17-7e2a-75f6b6e8d0a5 AT jdrake DOT com>
<bb65b74c-3216-0a61-c29d-6623395bb8bb AT jdrake DOT com> <aEzu40MSD4NQBJIY AT xps13>
Organization: Systematic Software
In-Reply-To: <aEzu40MSD4NQBJIY@xps13>
X-Rspamd-Server: rspamout03
X-Rspamd-Queue-Id: C88E92002F
X-Stat-Signature: wmfrc9k66fjyj7tjechhasgz5di47bxn
X-Session-Marker: 427269616E2E496E676C69734053797374656D6174696353572E61622E6361
X-Session-ID: U2FsdGVkX1+dkF0ZlgEcIwy1/28jOiMWWOSdQBRA/Ck=
X-HE-Tag: 1749925798-371365
X-HE-Meta: U2FsdGVkX18cpvJAYMoFrxGIM7zJf9NaYYpAOvmvrMAwcEdwzaseWnxlHfoHeRBzdf2rpsyX4W0m7aWOhruILNZxN2u0J6WFEb2q/TeJevPUuTBW/MwPivkXKOCx3ItO/gd5TORTIk1kAHPX2e5ewyPpbCFXBosrXpExzKD7A3J0WuJ0uEsudTo+SfMcjBB6T/j5mS5BKWgbZn0uSvC4KGqrJ4bgQ5/cv44dxRZvzNTML9ZbgB9zNlW5aeB33Tdj9ObarUe2fjY3AfbFzt5R1WZevJMy/h0BkiMqVt4ZFuYTkWew1Zq5hvcnO5ZsyO4FZodm1hAdulY1WlXG1G0Sz/whDKpToEX3m4nM1wnCz/2UdjYza1IJkQn8sFwUuSSmhTrO6gXAttm2Fe1xVAL9hSl/xHOIq/lErn63fIDthEcr6+FmIgC3Ejm+bWk0xgfMzyycKLCrFxxvE62AxwqhVK6Q8lcrgNl7ywSsdHRKwJ0ObPjAafRW8K5omDuaR2gNKZh32kPog4Q=
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Brian Inglis via Cygwin <cygwin AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
Cc: Brian Inglis <Brian DOT Inglis AT SystematicSW DOT ab DOT ca>
Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 55EIUTF02474160

On 2025-06-13 21:39, Glenn Strauss via Cygwin wrote:
> On Fri, Jun 13, 2025 at 02:25:17PM -0700, Jeremy Drake via Cygwin wrote:
>> On Fri, 13 Jun 2025, Jeremy Drake wrote:
>>
>>> I am working on some posix_spawn tests for the new stc repository [1], and
>>> making sure they behave the same between Cygwin and Linux.  I found one
>>> case (so far) which does not: passing NULL for argument "envp" to
>>> posix_spawn.
>>>
>>> In Cygwin, this results in the child inheriting the environment from the
>>> caller (same as passing "environ"), but on Linux this results in the child
>>> getting an empty environment (same as passing a char *envp[] = {NULL}).
>>>
>>> The Open Group doc on posix_spawn[2] doesn't seem to say anything about
>>> the potential for envp being NULL, but does mention
>>>
>>>> For the Ada language binding for Start_Process to be implemented with
>>>> posix_spawn(), that binding would need to explicitly pass an empty
>>>> signal mask and the parent's environment to posix_spawn() whenever the
>>>> caller of Start_Process allowed these arguments to default, since
>>>> posix_spawn() does not provide such defaults.
>>>
>>> That at least implies that passing NULL does not default to using the
>>> parent's environment.
>>>
>>> Thoughts?  Is this a bug in Cygwin, or "undefined behavior" that it's
>>> perfectly within its rights to do whatever it feels like in response
>>> (empty environment or inherited environment, or crash every second
>>> Tuesday)?
>>
>> Oops, I forgot my footnote links:
>>
>> [1]: https://cygwin.com/cgit/cygwin-apps/stc/
>> [2]: https://pubs.opengroup.org/onlinepubs/007904975/functions/posix_spawn.html

Latest Issue 8 2024 SUSV5:

https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_spawn.html

says envp is pointer to char * array.

> The man pages from different OS contain something like (from Linux):
> 
>     The argument envp is an array of character pointers to null-terminated strings. These strings constitute the environment for the new
>     process image. The environment array is terminated by a null pointer.
> 
> I have never interpreted NULL as a valid value for envp.
> I think the behavior is unspecified, and could segfault.
> If caller intends an empty environment, then caller should pass:
>    char *e[] = { NULL };

Could also pass a pointer to the final NULL pointer in environ to avoid defining 
your own.
> Therefore, in lighttpd's portability wrapper for fork-execve,
> passing NULL for envp (to my wrapper) is used to inherit default env
> from current process (char **environ), whether lighttpd uses
> posix_spawn() or execve().  This is the same behavior you described
> for Cygwin, though lighttpd passes `environ` to posix_spawn(), not NULL.
-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                 -- Antoine de Saint-Exupéry

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

- Raw text -


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