From patchwork Mon May 9 09:30:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1628437 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=swnnOEkZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KxbWQ4f2Cz9sGJ for ; Mon, 9 May 2022 19:30:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5292D3856263 for ; Mon, 9 May 2022 09:30:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5292D3856263 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652088638; bh=54oFykQYmm4MiJErt1YxAcUyHW8y5Apmk4VuXr/4AhQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=swnnOEkZJsUevFdQvYsXnQXhDfNRE3Zdp5I2D1Do20PzO2plTgH5/qhRYF3CVA4WN hQG4VJVRxQFlV4GPmhPrgu+2g3kCZT+ZF/l5liWEvDfLyx/df1ZFBq9iu7ME7Uay3g x1Rzs1SZYfJm4p5IvwcWFpVKjWeKUOxDUL5Sd2KE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 6B4773856273 for ; Mon, 9 May 2022 09:30:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6B4773856273 Received: by mail-wr1-x434.google.com with SMTP id q23so18555992wra.1 for ; Mon, 09 May 2022 02:30:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=54oFykQYmm4MiJErt1YxAcUyHW8y5Apmk4VuXr/4AhQ=; b=NojLxF6tLZH/mHOFRJWlEwWNC1UXFPU2D+VNzNJWQORIg8dy+MdzRHhklNlgcMjUms Roh2ZSgDX4AJqIRFDMiDEXAD/JDmIgP/n7bh6N8EAemXA4xM7enoEVs9n3r76d3lEFh0 jSib5iD1GPd2KpCWS4+hbsFyUZ9LyA5Dwp1MCmdd1U0SyPid5FQ8oxHTB3OQga2CIviT YADZ0tgr4fxvtE4S389N5e3pmGvB0Rb8bKDC5eFwc0lVXG9QDu/KrjZsXOr7+UY0Trqp KXPfkJO6+vU7/izqULBnBVvl/ECWLffbmIM+qJUqjsnXrfLxGcVbK5sSpxE2ZN2fRKAE kOFw== X-Gm-Message-State: AOAM533D1RYmAIXnm8mjx3D+0d+kr+LKSw5/TW2Xyn8nyD2GHNm6NQfN 72oLpZ7MYfvdw3Ui240qeZ7oP8p3+z2UFw== X-Google-Smtp-Source: ABdhPJyRpox/CtmdToo5ZvJuEZwNPQEXFLXqzucdesOTwqBQdJDkMyqz46azUgs7H6fPztx3qUDk+Q== X-Received: by 2002:a5d:6489:0:b0:20c:6b7d:1bab with SMTP id o9-20020a5d6489000000b0020c6b7d1babmr12742764wri.449.1652088611577; Mon, 09 May 2022 02:30:11 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id n13-20020a056000170d00b0020c5253d911sm10850926wrc.93.2022.05.09.02.30.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:30:10 -0700 (PDT) Date: Mon, 9 May 2022 09:30:10 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Stabilize exit code on close process Message-ID: <20220509093010.GA3184054@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Dmitriy Anisimkov Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Call Kill before close input handler in Close routine. Otherwise close input handler can terminate process before Kill and exit code became unpredictable. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/g-expect.adb (Close): Call Kill before Close_Input. diff --git a/gcc/ada/libgnat/g-expect.adb b/gcc/ada/libgnat/g-expect.adb --- a/gcc/ada/libgnat/g-expect.adb +++ b/gcc/ada/libgnat/g-expect.adb @@ -222,6 +222,10 @@ package body GNAT.Expect is Next_Filter : Filter_List; begin + if Descriptor.Pid > 0 then -- see comment in Send_Signal + Kill (Descriptor.Pid, Sig_Num => 9, Close => 0); + end if; + Close_Input (Descriptor); if Descriptor.Error_Fd /= Descriptor.Output_Fd @@ -234,12 +238,6 @@ package body GNAT.Expect is Close (Descriptor.Output_Fd); end if; - -- ??? Should have timeouts for different signals - - if Descriptor.Pid > 0 then -- see comment in Send_Signal - Kill (Descriptor.Pid, Sig_Num => 9, Close => 0); - end if; - GNAT.OS_Lib.Free (Descriptor.Buffer); Descriptor.Buffer_Size := 0;