diff mbox series

[Ada] Stabilize exit code on close process

Message ID 20220509093010.GA3184054@adacore.com
State New
Headers show
Series [Ada] Stabilize exit code on close process | expand

Commit Message

Pierre-Marie de Rodat May 9, 2022, 9:30 a.m. UTC
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 mbox series

Patch

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;