+2019-09-17 Vadim Godunko <godunko@adacore.com>
+
+ * libgnat/g-exptty.ads (Close_Input): New subprogram.
+ * libgnat/g-exptty.adb (Close_Input): New subprogram.
+ (Close): Move close of TTY to Close_Input.
+ * terminals.c (__gnat_close_tty): Set file descriptors to
+ invalid value after close.
+
2019-09-17 Vadim Godunko <godunko@adacore.com>
* libgnat/g-expect.adb (Expect_Internal): Try to call 'poll' few
procedure Free_Process (Process : System.Address);
pragma Import (C, Free_Process, "__gnat_free_process");
- procedure Close_TTY (Process : System.Address);
- pragma Import (C, Close_TTY, "__gnat_close_tty");
-
begin
-- If we haven't already closed the process
Status := Descriptor.Exit_Status;
end if;
- if not On_Windows then
- Close_TTY (Descriptor.Process);
- end if;
-
Free_Process (Descriptor.Process'Address);
Descriptor.Process := System.Null_Address;
Close (Descriptor, Status);
end Close;
+ -----------------
+ -- Close_Input --
+ -----------------
+
+ overriding procedure Close_Input
+ (Descriptor : in out TTY_Process_Descriptor)
+ is
+ function TTY_FD
+ (Handle : System.Address) return GNAT.OS_Lib.File_Descriptor;
+ pragma Import (C, TTY_FD, "__gnat_tty_fd");
+
+ procedure Close_TTY (Process : System.Address);
+ pragma Import (C, Close_TTY, "__gnat_close_tty");
+
+ begin
+ if not On_Windows and then Descriptor.Process /= System.Null_Address then
+ -- Check whether input/output/error streams use master descriptor and
+ -- reset corresponding members.
+
+ if Descriptor.Input_Fd = TTY_FD (Descriptor.Process) then
+ Descriptor.Input_Fd := Invalid_FD;
+ end if;
+
+ if Descriptor.Output_Fd = TTY_FD (Descriptor.Process) then
+ Descriptor.Output_Fd := Invalid_FD;
+ end if;
+
+ if Descriptor.Error_Fd = TTY_FD (Descriptor.Process) then
+ Descriptor.Error_Fd := Invalid_FD;
+ end if;
+
+ -- Close master descriptor.
+
+ Close_TTY (Descriptor.Process);
+ end if;
+
+ -- Call parent's implementation to close all remaining descriptors.
+
+ Process_Descriptor (Descriptor).Close_Input;
+ end Close_Input;
+
-----------------------------
-- Close_Pseudo_Descriptor --
-----------------------------
*/
void __gnat_close_tty (pty_desc* desc)
{
- if (desc->master_fd >= 0) close (desc->master_fd);
- if (desc->slave_fd >= 0) close (desc->slave_fd);
+ if (desc->master_fd >= 0) { close (desc->master_fd); desc->master_fd = -1; }
+ if (desc->slave_fd >= 0) { close (desc->slave_fd); desc->slave_fd = -1; }
}
/* __gnat_tty_name - return slave side device name