From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2114.outbound.protection.outlook.com [40.107.237.114]) by sourceware.org (Postfix) with ESMTPS id 128EC3858D35 for ; Thu, 30 Jul 2020 23:04:35 +0000 (GMT) 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 Received: from MN2PR04MB6176.namprd04.prod.outlook.com (2603:10b6:208:e3::13) by MN2PR04MB6000.namprd04.prod.outlook.com (2603:10b6:208:d9::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.20; Thu, 30 Jul 2020 23:04:32 +0000 Received: from MN2PR04MB6176.namprd04.prod.outlook.com ([fe80::184d:a265:1d48:499a]) by MN2PR04MB6176.namprd04.prod.outlook.com ([fe80::184d:a265:1d48:499a%7]) with mapi id 15.20.3239.019; Thu, 30 Jul 2020 23:04:32 +0000 Subject: Re: Synchronization problem with posix_spawn To: cygwin@cygwin.com References: <864b3031-9fc8-beb3-ba7c-1ade4c31a288@cornell.edu> <20200730115913.GL4206@calimero.vinschen.de> <20200730171723.GA460314@calimero.vinschen.de> From: Ken Brown 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> Content-Type: multipart/mixed; boundary="------------21AFCDD99193351E44B628B9" Content-Language: en-US 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 Received: from [192.168.0.17] (68.175.129.7) by CH2PR10CA0023.namprd10.prod.outlook.com (2603:10b6:610:4c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 23:04:31 +0000 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: 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@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jul 2020 23:04:38 -0000 --------------21AFCDD99193351E44B628B9 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Hi Corinna, On 7/30/2020 1:17 PM, Corinna Vinschen wrote: > Hi Ken, > > 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.  [...] >>> I just took a look at the source, and I see that posix_spawn was taken from >>> FreeBSD. Does FreeBSD have the same problem? Should applications just be >>> aware of this issue and insert a sleep after posix_spawn before sending >>> 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). > > 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. > > Can you give it a try? It looks like something further is needed: 'wait' doesn't seem to recognize the spawned process. I'm attaching a second test case. This spawns a "sleep 10" process and then waits for termination. If I run it on Cygwin, it returns immediately like 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 #include #include #include #include #include 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--