www.delorie.com/archives/browse.cgi | search |
DMARC-Filter: | OpenDMARC Filter v1.4.2 delorie.com 55F0jOQV2675165 |
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 55F0jOQV2675165 |
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=L/xXlrLj | |
X-Recipient: | archive-cygwin AT delorie DOT com |
DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org 15A633873DC1 |
DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; |
s=default; t=1749948322; | |
bh=ObHg0g3e0QqsZLY69me7DZ5IULAvK3BdZ/YwGczswA0=; | |
h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: | |
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: | |
From; | |
b=L/xXlrLjmf+jkNhgrjuz/KEtLmY7b8KtiaRR/iMYv4BqImLxWHxBsL/3q5gWKWV5+ | |
gzT1hoVQ6moI5rqvI0L1DKTRLhQ0/imShpSE5jccX+CsRYhHtJ0TYuaWJk/iw9S6wh | |
7afGdC6QkXBSsB1Dbm/sE0NMFTXOvGhux6uMcqfM= | |
X-Original-To: | cygwin AT cygwin DOT com |
Delivered-To: | cygwin AT cygwin DOT com |
DMARC-Filter: | OpenDMARC Filter v1.4.2 sourceware.org 6032939694E4 |
ARC-Filter: | OpenARC Filter v1.0.0 sourceware.org 6032939694E4 |
ARC-Seal: | i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749948230; cv=none; |
b=hersDsnPOCQQ/c3XNlGW1W/pEQvUt2vxiT5fac54SJPHkDtSNlK8N04pJSiI5hXPfMvyMFD3Rnf3KepT7rkLsc/14X6o2mh4TOHvVG0HiB4x7ZFhfHnZDwPQYzpss5IJ2aMXVE2dTuEo6p/ydWuO5+A1MGxjQqnOP/iVPC61jEY= | |
ARC-Message-Signature: | i=1; a=rsa-sha256; d=sourceware.org; s=key; |
t=1749948230; c=relaxed/simple; | |
bh=IveY5HGd9AmlVE4gQxQ1ExQkkKGXonFRQkDs54IO3yU=; | |
h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; | |
b=hOIegY5QqpmuqEiYwGtq2mf/oMmUaOw7JDDZ1jWtpQzeNuYF84vOj/ZsqJl9KqqYKRqtEh6G1mekCpz1w5TU2tapcdx8Eii02pVIhCvUJuFSYt+DM+F2NfW1K+jUQjowQ5etsIjLJMwTvKK9pARKGla/5iAdQS3gRGXNpyeva4M= | |
ARC-Authentication-Results: | i=1; server2.sourceware.org |
DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org 6032939694E4 |
Date: | Sat, 14 Jun 2025 20:43:46 -0400 |
To: | cygwin AT cygwin DOT com |
Subject: | Re: posix_spawn difference from Linux |
Message-ID: | <aE4XQsrd_UH5H029@xps13> |
References: | <35d5a3b2-e060-cb17-7e2a-75f6b6e8d0a5 AT jdrake DOT com> |
<bb65b74c-3216-0a61-c29d-6623395bb8bb AT jdrake DOT com> | |
<aEzu40MSD4NQBJIY AT xps13> | |
<11206d22-8533-42d8-afd5-cd1b2056cb59 AT SystematicSW DOT ab DOT ca> | |
MIME-Version: | 1.0 |
In-Reply-To: | <11206d22-8533-42d8-afd5-cd1b2056cb59@SystematicSW.ab.ca> |
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: | Glenn Strauss via Cygwin <cygwin AT cygwin DOT com> |
Reply-To: | Glenn Strauss <gs-cygwin DOT com AT gluelogic DOT com> |
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> |
On Sat, Jun 14, 2025 at 12:29:57PM -0600, Brian Inglis via Cygwin wrote: > 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. Yes. And to clarify for pedantic correctness, the envp pointer should be stable during the fork, so it is best to avoid using the stack. One solution, as Brian said, is to pass a pointer to the NULL at the end of environ (which is still not guaranteed static), or one could use static char *empty_envp[] = { NULL }; and pass empty_envp, which is persistent and stable. Cheers, Glenn -- 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
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |