delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2020/07/30/19:05:24

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74076385700E
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1596150280;
bh=Y1NHbOT4IvIpv39rTYB1KSPRN11nvvcUGfcFBubjvSg=;
h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=pBgGRBLH/Tfymvf9ozUe7Fc/TykxkLWGqg2KU3JafLeIyMvCcpUZhebeliJ18yRHm
cdjFbh3a8x1FtObHcI7O7cEV8nOlgPHNz3WQ6A/R50KH4Mlne8lzLRAnhadKn0uG8R
2rFpesyQNZdJrWLmRbvjt6kJ5EAaHwY1tKzYkedU=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 128EC3858D35
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=fKSzF6aa4b1UQ8alo8O1haUYpWbhkL/3SvzgJ095XgIhElM4LALmzMg3PRGHrTViP73PfgLirKsk3ukRJ1iwkHQUDT9MUFq2bRUPgcvL11lJddRWDf9iP7WYIIypcwbKUXsQ3dbmJuzMsFL1WJt5IsFjTwKP28LZu7SV8cSMocKKgG5cOWW55VFklJKfPtoGiJtODgqUu++Y5/C9YFUS9stoe6vPuJ/Z05GsAxkRFOHFQVvQJc3optDzDIrhrp+fQyeBabKk8yo51lV+m/8wj1LtQDlGVTayB8F4F/XFrQlIFH6PGrcV9BtlElKtgou1B6nngzij8pKecF+fB+t1cQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=7UnEo6fFaulBiQzx/X3XTZfWtFxFFXMgOkuZHnXbiVk=;
b=C8iwoWVu03d1zxl66I+E1tBMajQbq85VmIIZ9v86wctBWuGw7K1BmWkVR80Zwzc8zUWFx5aKHYlJztIiFh5+y5B04Mbx+K6ieoJwaD7TKIrwfHGW4kYHQMXhovrr1IjFjtp/vYvJRBbO9iufKab/sFILqylPNT3oLUKbvLIgBcibH3WOUA6rIana1BZgBM9igPevGbhIv7Vj25PRa6zh7QSLd60iCp3Ohnk7TBNTs55mBoYdBQCnX5UDArrqApnTwsusMmPWFNnysNJhhyFWG8xEpkVGrov7EMsVzJW7CyUfnYrvnsQAX/pw+CrM9TtiFF5XHJJfpf4chAzZeWSojQ==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu;
dkim=pass header.d=cornell.edu; arc=none
Subject: Re: Synchronization problem with posix_spawn
To: cygwin AT cygwin DOT com
References: <b1992e8b-d2e8-9c44-8f93-a270d5a879ed AT cornell DOT edu>
<864b3031-9fc8-beb3-ba7c-1ade4c31a288 AT cornell DOT edu>
<20200730115913 DOT GL4206 AT calimero DOT vinschen DOT de>
<20200730171723 DOT GA460314 AT calimero DOT vinschen DOT de>
Message-ID: <86051625-646d-065a-8543-1c3086411d3d@cornell.edu>
Date: Thu, 30 Jul 2020 19:04:30 -0400
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
In-Reply-To: <20200730171723.GA460314@calimero.vinschen.de>
X-ClientProxiedBy: CH2PR10CA0023.namprd10.prod.outlook.com
(2603:10b6:610:4c::33) To MN2PR04MB6176.namprd04.prod.outlook.com
(2603:10b6:208:e3::13)
MIME-Version: 1.0
X-MS-Exchange-MessageSentRepresentingType: 1
X-Originating-IP: [68.175.129.7]
X-MS-PublicTrafficType: Email
X-MS-Office365-Filtering-Correlation-Id: 2f2cd179-8df7-4534-1892-08d834dceb87
X-MS-TrafficTypeDiagnostic: MN2PR04MB6000:
X-Microsoft-Antispam-PRVS: <MN2PR04MB6000754049CA22BDF4627053D8710 AT MN2PR04MB6000 DOT namprd04 DOT prod DOT outlook DOT com>
X-MS-Oob-TLC-OOBClassifiers: OLM:10000;
X-MS-Exchange-SenderADCheck: 1
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: bUmuFnB8gNWF6GewXYFToZ1dBe5U9xpQddgphjiEgM3kuBpIg2iB/lG1j588eRU7WIciscEYojHFwf6og696852qbyDFb0Nr0NzfTS2jvftBdps7mv0I2AsmGWhKdcZnDpwXftpe2+o9SNhJvDRtavEnL9uOQwNTPw8Qn+9NJuN+G1IYwDBdddk6mznnvtOvkRpY47vT9hXnKb4TuUZLaMiAZDHr7u8G22Z7FVxRycjQaIOmxXdwWXNQe9hPvkT0CMlAvnvEQeym8KF/0/nUeP5ds7nS58WcW9QBa/NjWONEHV3PCObCL1th0amvPul3MrUh/T7wlIm39KmlRqbgXh21ojVbDbfOspDDxYcHnCmMm7qZz4sB9Mcs8GtYteq7
X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:MN2PR04MB6176.namprd04.prod.outlook.com; PTR:; CAT:NONE;
SFTY:;
SFS:(4636009)(366004)(396003)(39860400002)(376002)(136003)(346002)(186003)(16526019)(6486002)(36756003)(8676002)(53546011)(2906002)(31686004)(8936002)(33964004)(83380400001)(6916009)(52116002)(26005)(75432002)(235185007)(2616005)(956004)(66476007)(66556008)(66616009)(66946007)(16576012)(86362001)(31696002)(786003)(316002)(478600001)(5660300002)(43740500002);
DIR:OUT; SFP:1102;
X-MS-Exchange-AntiSpam-MessageData: 6vyR1zmbDcwJssz8GHRH1hfJyY5BsUsiMAqs4y7UjiutsmekoUcbEC+YWXVzsB8OROtL6wPk6KJKWfxyo6YrRD8UmYWwnpx0dgy2GTQZ3QmCPdbcNAK77eU7dSEux6ainw3zd5192q0YEITowPh7dOOT7m+UpcKsGefIIqLYvSDz7JB3GGHWD/jYYbuMzCs79uljZ0Xs/2qygqa7qlu79ckKfQmHAJHwyeW80RBmHCVejWKZEyO60ME5foq6mS6QB+1EErxaceXgccBHZGfPBwD5diRFlA8YrbwGGdxonDELCWAnohtoH/I4p7ei1mghXCw0ReIRrVgOH91SJ8Apkl4wF/BzMGKy3RfX08XM38mjZQ7w9GwlJgff+pcDQmnmeye2k6WabJpsAyCXohR+eFj1tUcc5t+C8wXJA4tAYNWRJSTQd6goYuOQbRigpM0xA9CF1/C0impc6NZQCN7qljEIbwjKM4LU5elVIOWUqEZnFYl/DoOaFcV4vGvTOXNIiAeJhfREoRWMebpL0/G9gH4cezqgx+GR1DZIY9fk5nsmJQZqJLg2kxQ/stvUxuvAzS4exraOsVhtUtO3BtcpW1xuydfxzodRYqBDlGGOFotacZisGrBxaXDFRrUHxhGa6fOIyUgK0Ul/A9FWOs7fIg==
X-OriginatorOrg: cornell.edu
X-MS-Exchange-CrossTenant-Network-Message-Id: 2f2cd179-8df7-4534-1892-08d834dceb87
X-MS-Exchange-CrossTenant-AuthSource: MN2PR04MB6176.namprd04.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 23:04:32.5601 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 5d7e4366-1b9b-45cf-8e79-b14b27df46e1
X-MS-Exchange-CrossTenant-MailboxType: HOSTED
X-MS-Exchange-CrossTenant-UserPrincipalName: ZI/lnQFqfvxW8A9ExmzmQx3DPefSdBBIwVFyWLOSX1skdyG8ORtDNWk3getquuTOoBDD6TC19hdd0FkpSdKTNQ==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB6000
X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DKIM_INVALID,
DKIM_SIGNED, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, MSGID_FROM_MTA_HEADER,
NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS,
TXREP autolearn=no autolearn_force=no version=3.4.2
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
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: Ken Brown via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Ken Brown <kbrown AT cornell DOT edu>
Errors-To: cygwin-bounces AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces AT cygwin DOT com>

--------------21AFCDD99193351E44B628B9
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: quoted-printable

Hi Corinna,

On 7/30/2020 1:17 PM, Corinna Vinschen wrote:
> Hi Ken,
>=20
> On Jul 30 13:59, Corinna Vinschen wrote:
>> On Jul 29 19:12, Ken Brown via Cygwin wrote:
>>> On 7/29/2020 4:17 PM, Ken Brown via Cygwin wrote:
>>>> posix_spawn(p) returns before the spawned process is fully up and
>>>> running.=A0 [...]
>>> I just took a look at the source, and I see that posix_spawn was take=
n from
>>> FreeBSD.  Does FreeBSD have the same problem?  Should applications ju=
st be
>>> aware of this issue and insert a sleep after posix_spawn before sendi=
ng
>>> signals?
>>
>> Actually, this is a Cygwin problem.  I just had a look into the
>> newlib implementation myself, and it turns out that the code,
>> in particular the do_posix_spawn() function, is BSD specific.  It
>> relies on the BSD implementation of vfork(2).  Cygwin's vfork(2)
>> on the other hand, is NOT following the historic idea of the
>> BSD vfork(2), rather it's equivalent to fork(2).  This is
>> POSIX compliant, but certainly the reliance of the BSD vfork
>> behaviour makes do_posix_spawn() as it's implemented right now,
>> not overly functional for Cygwin.
>>
>> IOW, we need a Cygwin-specific do_posix_spawn() using fork(2)
>> in conjunction with some synchronization the BSD function
>> gets "for free" by using its specific vfork(2).
>=20
> Below is a POC implementation for a Cygwin-specific do_posix_spawn().
> If this does the trick (at least your testcase works in my testing),
> then I'm planning to move the function over to the winsup/cygwin dir
> so it can be streamlined further.
>=20
> Can you give it a try?

It looks like something further is needed: 'wait' doesn't seem to recogni=
ze the=20
spawned process.

I'm attaching a second test case.  This spawns a "sleep 10" process and t=
hen=20
waits for termination.  If I run it on Cygwin, it returns immediately lik=
e this:

   $ ./spawn_test2
   wait: No child processes
   sleep 10 exited normally with status 0

and the sleep process is still running.  If I run it on Linux, I see

   $ ./spawn_test2
   sleep 10 exited normally with status 0

if I let the sleep process run to completion, or

   $ ./spawn_test2
   sleep 10 exited due to signal 15

if I run 'pkill sleep' in another terminal.

Ken

--------------21AFCDD99193351E44B628B9
Content-Type: text/plain; charset=UTF-8;
 name="spawn_test2.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="spawn_test2.c"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <spawn.h>
#include <signal.h>
#include <sys/wait.h>

extern char **environ;

pid_t
run_sleep ()
{
  pid_t pid;
  char *argv[] = { "sleep", "10", NULL };
  int err = posix_spawnp (&pid, "/bin/sleep", NULL, NULL, argv, environ);
  if (err == 0)
    return pid;
  else
    {
      printf ("posix_spawnp: %s\n", strerror (err));
      exit (1);
    }
}

int
main ()
{
  int status;
  pid_t pid = run_sleep ();
  if (wait (&status) < 0)
    perror ("wait");
  if (WIFEXITED (status))
    printf ("sleep 10 exited normally with status %d\n", WEXITSTATUS (status));
  else if (WIFSIGNALED (status))
    printf ("sleep 10 exited due to signal %d\n", WTERMSIG (status));
  else
    printf ("????\n");
}

--------------21AFCDD99193351E44B628B9
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

--
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

--------------21AFCDD99193351E44B628B9--

- Raw text -


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