]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Stabilize exit code on close process
authorDmitriy Anisimkov <anisimko@adacore.com>
Tue, 21 Dec 2021 06:01:32 +0000 (12:01 +0600)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 9 May 2022 09:27:28 +0000 (09:27 +0000)
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

index e43ef4f352df5c2943d2cac7b8f4602f01d0a408..1c5b8312d7c5363e2b1f0638819a2cc2cd7e4a4a 100644 (file)
@@ -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;