From 9a6f7575c153e7036152002bb7b58166762592f1 Mon Sep 17 00:00:00 2001 From: Dmitriy Anisimkov Date: Tue, 21 Dec 2021 12:01:32 +0600 Subject: [PATCH] [Ada] Stabilize exit code on close process Call Kill before close input handler in Close routine. Otherwise close input handler can terminate process before Kill and exit code became unpredictable. gcc/ada/ * libgnat/g-expect.adb (Close): Call Kill before Close_Input. --- gcc/ada/libgnat/g-expect.adb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gcc/ada/libgnat/g-expect.adb b/gcc/ada/libgnat/g-expect.adb index e43ef4f352d..1c5b8312d7c 100644 --- 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;