-- --
-- B o d y --
-- --
--- Copyright (C) 2000-2003 Ada Core Technologies, Inc. --
+-- Copyright (C) 2000-2005 Ada Core Technologies, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- --
------------------------------------------------------------------------------
-with System; use System;
-with Ada.Calendar; use Ada.Calendar;
+with System; use System;
+with Ada.Calendar; use Ada.Calendar;
with GNAT.IO;
-with GNAT.OS_Lib; use GNAT.OS_Lib;
-with GNAT.Regpat; use GNAT.Regpat;
+with GNAT.OS_Lib; use GNAT.OS_Lib;
+with GNAT.Regpat; use GNAT.Regpat;
with Unchecked_Deallocation;
------------------
function Get_Error_Fd
- (Descriptor : Process_Descriptor)
- return GNAT.OS_Lib.File_Descriptor
- is
+ (Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor is
begin
return Descriptor.Error_Fd;
end Get_Error_Fd;
------------------
function Get_Input_Fd
- (Descriptor : Process_Descriptor)
- return GNAT.OS_Lib.File_Descriptor
- is
+ (Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor is
begin
return Descriptor.Input_Fd;
end Get_Input_Fd;
-------------------
function Get_Output_Fd
- (Descriptor : Process_Descriptor)
- return GNAT.OS_Lib.File_Descriptor
- is
+ (Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor is
begin
return Descriptor.Output_Fd;
end Get_Output_Fd;
-------------
function Get_Pid
- (Descriptor : Process_Descriptor)
- return Process_Id
- is
+ (Descriptor : Process_Descriptor) return Process_Id is
begin
return Descriptor.Pid;
end Get_Pid;
Arg : String_Access;
Arg_List : String_List (1 .. Args'Length + 2);
- C_Arg_List : aliased array (1 .. Args'Length + 2) of System.Address;
+ C_Arg_List : aliased array (1 .. Args'Length + 2) of System.Address;
Command_With_Path : String_Access;
----------
procedure Send
- (Descriptor : in out Process_Descriptor;
- Str : String;
- Add_LF : Boolean := True;
+ (Descriptor : in out Process_Descriptor;
+ Str : String;
+ Add_LF : Boolean := True;
Empty_Buffer : Boolean := False)
is
Full_Str : constant String := Str & ASCII.LF;
Pipe2 : access Pipe_Type;
Pipe3 : access Pipe_Type)
is
+ Status : Boolean;
+
begin
-- Create the pipes
return;
end if;
+ -- Record the 'parent' end of the two pipes in Pid:
+ -- Child stdin is connected to the 'write' end of Pipe1;
+ -- Child stdout is connected to the 'read' end of Pipe2.
+ -- We do not want these descriptors to remain open in the child
+ -- process, so we mark them close-on-exec/non-inheritable.
+
Pid.Input_Fd := Pipe1.Output;
+ Set_Close_On_Exec (Pipe1.Output, True, Status);
Pid.Output_Fd := Pipe2.Input;
+ Set_Close_On_Exec (Pipe2.Input, True, Status);
if Err_To_Out then
+
+ -- Reuse the standard output pipe for standard error
+
Pipe3.all := Pipe2.all;
else
+
+ -- Create a separate pipe for standard error
+
if Create_Pipe (Pipe3) /= 0 then
return;
end if;
end if;
+ -- As above, we record the proper fd for the child's
+ -- standard error stream.
+
Pid.Error_Fd := Pipe3.Input;
+ Set_Close_On_Exec (Pipe3.Input, True, Status);
end Set_Up_Communications;
----------------------------------