From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 115387 invoked by alias); 18 Sep 2019 08:41:57 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 115330 invoked by uid 89); 18 Sep 2019 08:41:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,SPF_NEUTRAL autolearn=ham version=3.3.1 spammy=died X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (209.51.188.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Sep 2019 08:41:55 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAVVB-0008HP-0R for gcc-patches@gcc.gnu.org; Wed, 18 Sep 2019 04:39:54 -0400 Received: from rock.gnat.com ([205.232.38.15]:43758) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAVVA-0008ES-72 for gcc-patches@gcc.gnu.org; Wed, 18 Sep 2019 04:39:52 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id EC9C2117CC4; Wed, 18 Sep 2019 04:39:44 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 71MZBkKS0B4S; Wed, 18 Sep 2019 04:39:44 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id D7655117C70; Wed, 18 Sep 2019 04:39:44 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id D64AD702; Wed, 18 Sep 2019 04:39:44 -0400 (EDT) Date: Wed, 18 Sep 2019 08:41:00 -0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Vadim Godunko Subject: [Ada] Raise exception on call to Expect for a dead process Message-ID: <20190918083944.GA145079@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2oS5YaxWCcQjTEyO" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 205.232.38.15 X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg01076.txt.bz2 --2oS5YaxWCcQjTEyO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 510 Call to Expect for a dead process results in SIGBUS signal on Linux systems. Process_Died exception is raised in this case now. Tested on x86_64-pc-linux-gnu, committed on trunk 2019-09-18 Vadim Godunko gcc/ada/ * libgnat/g-expect.adb (Expect_Internal): Don't include invalid file descriptors into the set of file descriptors for Poll. Raise Process_Died exception when computed set of file descriptors to monitor is empty. gcc/testsuite/ * gnat.dg/expect4.adb: New testcase. --2oS5YaxWCcQjTEyO Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" Content-length: 1655 --- gcc/ada/libgnat/g-expect.adb +++ gcc/ada/libgnat/g-expect.adb @@ -653,7 +653,9 @@ package body GNAT.Expect is begin for J in Descriptors'Range loop - if Descriptors (J) /= null then + if Descriptors (J) /= null + and then Descriptors (J).Output_Fd /= Invalid_FD + then Fds (Fds'First + Fds_Count) := Descriptors (J).Output_Fd; Fds_To_Descriptor (Fds'First + Fds_Count) := J; Fds_Count := Fds_Count + 1; @@ -667,6 +669,14 @@ package body GNAT.Expect is end if; end loop; + if Fds_Count = 0 then + -- There are no descriptors to monitor, it means that process died. + + Result := Expect_Process_Died; + + return; + end if; + declare Buffer : aliased String (1 .. Buffer_Size); -- Buffer used for input. This is allocated only once, not for --- /dev/null new file mode 100644 +++ gcc/testsuite/gnat.dg/expect4.adb @@ -0,0 +1,35 @@ +-- { dg-do run } + +with GNAT.Expect.TTY; +with GNAT.OS_Lib; + +procedure Expect4 is + Pid : GNAT.Expect.TTY.TTY_Process_Descriptor; + Args : GNAT.OS_Lib.Argument_List (1 .. 0); + Result : GNAT.Expect.Expect_Match; + +begin + Pid.Non_Blocking_Spawn ("true", Args); + + begin + Pid.Expect (Result, ".*"); + + raise Program_Error; + + exception + when GNAT.Expect.Process_Died => + null; + end; + + begin + Pid.Expect (Result, ".*"); + + raise Program_Error; + + exception + when GNAT.Expect.Process_Died => + null; + end; + + Pid.Close; +end Expect4; \ No newline at end of file --2oS5YaxWCcQjTEyO--