1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- G N A T . E X P E C T --
9 -- Copyright (C) 2002-2005 Ada Core Technologies, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This is the VMS version.
36 with System
; use System
;
37 with Ada
.Calendar
; use Ada
.Calendar
;
40 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
41 with GNAT
.Regpat
; use GNAT
.Regpat
;
43 with Unchecked_Deallocation
;
45 package body GNAT
.Expect
is
47 type Array_Of_Pd
is array (Positive range <>) of Process_Descriptor_Access
;
49 Save_Input
: File_Descriptor
;
50 Save_Output
: File_Descriptor
;
51 Save_Error
: File_Descriptor
;
53 procedure Expect_Internal
54 (Descriptors
: in out Array_Of_Pd
;
55 Result
: out Expect_Match
;
57 Full_Buffer
: Boolean);
58 -- Internal function used to read from the process Descriptor.
60 -- Three outputs are possible:
61 -- Result=Expect_Timeout, if no output was available before the timeout
63 -- Result=Expect_Full_Buffer, if Full_Buffer is True and some characters
64 -- had to be discarded from the internal buffer of Descriptor.
65 -- Result=<integer>, indicates how many characters were added to the
66 -- internal buffer. These characters are from indexes
67 -- Descriptor.Buffer_Index - Result + 1 .. Descriptor.Buffer_Index
68 -- Process_Died is raised if the process is no longer valid.
70 procedure Reinitialize_Buffer
71 (Descriptor
: in out Process_Descriptor
'Class);
72 -- Reinitialize the internal buffer.
73 -- The buffer is deleted up to the end of the last match.
75 procedure Free
is new Unchecked_Deallocation
76 (Pattern_Matcher
, Pattern_Matcher_Access
);
78 procedure Call_Filters
79 (Pid
: Process_Descriptor
'Class;
81 Filter_On
: Filter_Type
);
82 -- Call all the filters that have the appropriate type.
83 -- This function does nothing if the filters are locked
85 ------------------------------
86 -- Target dependent section --
87 ------------------------------
89 function Dup
(Fd
: File_Descriptor
) return File_Descriptor
;
90 pragma Import
(C
, Dup
, "decc$dup");
92 procedure Dup2
(Old_Fd
, New_Fd
: File_Descriptor
);
93 pragma Import
(C
, Dup2
, "decc$dup2");
95 procedure Kill
(Pid
: Process_Id
; Sig_Num
: Integer);
96 pragma Import
(C
, Kill
, "decc$kill");
98 function Create_Pipe
(Pipe
: access Pipe_Type
) return Integer;
99 pragma Import
(C
, Create_Pipe
, "__gnat_pipe");
102 (Fds
: System
.Address
;
105 Is_Set
: System
.Address
) return Integer;
106 pragma Import
(C
, Poll
, "__gnat_expect_poll");
107 -- Check whether there is any data waiting on the file descriptor
108 -- Out_fd, and wait if there is none, at most Timeout milliseconds
109 -- Returns -1 in case of error, 0 if the timeout expired before
110 -- data became available.
112 -- Out_Is_Set is set to 1 if data was available, 0 otherwise.
114 function Waitpid
(Pid
: Process_Id
) return Integer;
115 pragma Import
(C
, Waitpid
, "__gnat_waitpid");
116 -- Wait for a specific process id, and return its exit code.
122 function "+" (S
: String) return GNAT
.OS_Lib
.String_Access
is
124 return new String'(S);
132 (P : GNAT.Regpat.Pattern_Matcher) return Pattern_Matcher_Access
135 return new GNAT.Regpat.Pattern_Matcher'(P
);
143 (Descriptor
: in out Process_Descriptor
;
144 Filter
: Filter_Function
;
145 Filter_On
: Filter_Type
:= Output
;
146 User_Data
: System
.Address
:= System
.Null_Address
;
147 After
: Boolean := False)
149 Current
: Filter_List
:= Descriptor
.Filters
;
153 while Current
/= null and then Current
.Next
/= null loop
154 Current
:= Current
.Next
;
157 if Current
= null then
158 Descriptor
.Filters
:=
159 new Filter_List_Elem
'
160 (Filter => Filter, Filter_On => Filter_On,
161 User_Data => User_Data, Next => null);
164 new Filter_List_Elem'
165 (Filter
=> Filter
, Filter_On
=> Filter_On
,
166 User_Data
=> User_Data
, Next
=> null);
170 Descriptor
.Filters
:=
171 new Filter_List_Elem
'
172 (Filter => Filter, Filter_On => Filter_On,
173 User_Data => User_Data, Next => Descriptor.Filters);
181 procedure Call_Filters
182 (Pid : Process_Descriptor'Class;
184 Filter_On : Filter_Type)
186 Current_Filter : Filter_List;
189 if Pid.Filters_Lock = 0 then
190 Current_Filter := Pid.Filters;
192 while Current_Filter /= null loop
193 if Current_Filter.Filter_On = Filter_On then
194 Current_Filter.Filter
195 (Pid, Str, Current_Filter.User_Data);
198 Current_Filter := Current_Filter.Next;
208 (Descriptor : in out Process_Descriptor;
209 Status : out Integer)
212 Close (Descriptor.Input_Fd);
214 if Descriptor.Error_Fd /= Descriptor.Output_Fd then
215 Close (Descriptor.Error_Fd);
218 Close (Descriptor.Output_Fd);
220 -- ??? Should have timeouts for different signals
221 Kill (Descriptor.Pid, 9);
223 GNAT.OS_Lib.Free (Descriptor.Buffer);
224 Descriptor.Buffer_Size := 0;
226 Status := Waitpid (Descriptor.Pid);
229 procedure Close (Descriptor : in out Process_Descriptor) is
232 Close (Descriptor, Status);
240 (Descriptor : in out Process_Descriptor;
241 Result : out Expect_Match;
243 Timeout : Integer := 10000;
244 Full_Buffer : Boolean := False)
248 Expect (Descriptor, Result, Never_Match, Timeout, Full_Buffer);
250 Expect (Descriptor, Result, Compile (Regexp), Timeout, Full_Buffer);
255 (Descriptor : in out Process_Descriptor;
256 Result : out Expect_Match;
258 Matched : out GNAT.Regpat.Match_Array;
259 Timeout : Integer := 10000;
260 Full_Buffer : Boolean := False)
263 pragma Assert (Matched'First = 0);
266 (Descriptor, Result, Never_Match, Matched, Timeout, Full_Buffer);
269 (Descriptor, Result, Compile (Regexp), Matched, Timeout,
275 (Descriptor : in out Process_Descriptor;
276 Result : out Expect_Match;
277 Regexp : GNAT.Regpat.Pattern_Matcher;
278 Timeout : Integer := 10000;
279 Full_Buffer : Boolean := False)
281 Matched : GNAT.Regpat.Match_Array (0 .. 0);
284 Expect (Descriptor, Result, Regexp, Matched, Timeout, Full_Buffer);
288 (Descriptor : in out Process_Descriptor;
289 Result : out Expect_Match;
290 Regexp : GNAT.Regpat.Pattern_Matcher;
291 Matched : out GNAT.Regpat.Match_Array;
292 Timeout : Integer := 10000;
293 Full_Buffer : Boolean := False)
296 Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access);
297 Try_Until : constant Time := Clock + Duration (Timeout) / 1000.0;
298 Timeout_Tmp : Integer := Timeout;
301 pragma Assert (Matched'First = 0);
302 Reinitialize_Buffer (Descriptor);
305 -- First, test if what is already in the buffer matches (This is
306 -- required if this package is used in multi-task mode, since one of
307 -- the tasks might have added something in the buffer, and we don't
308 -- want other tasks to wait for new input to be available before
309 -- checking the regexps).
312 (Regexp, Descriptor.Buffer (1 .. Descriptor.Buffer_Index), Matched);
314 if Descriptor.Buffer_Index >= 1 and then Matched (0).First /= 0 then
316 Descriptor.Last_Match_Start := Matched (0).First;
317 Descriptor.Last_Match_End := Matched (0).Last;
321 -- Else try to read new input
323 Expect_Internal (Descriptors, N, Timeout_Tmp, Full_Buffer);
325 if N = Expect_Timeout or else N = Expect_Full_Buffer then
330 -- Calculate the timeout for the next turn.
331 -- Note that Timeout is, from the caller's perspective, the maximum
332 -- time until a match, not the maximum time until some output is
333 -- read, and thus can not be reused as is for Expect_Internal.
335 if Timeout /= -1 then
336 Timeout_Tmp := Integer (Try_Until - Clock) * 1000;
338 if Timeout_Tmp < 0 then
339 Result := Expect_Timeout;
345 -- Even if we had the general timeout above, we have to test that the
346 -- last test we read from the external process didn't match.
349 (Regexp, Descriptor.Buffer (1 .. Descriptor.Buffer_Index), Matched);
351 if Matched (0).First /= 0 then
353 Descriptor.Last_Match_Start := Matched (0).First;
354 Descriptor.Last_Match_End := Matched (0).Last;
360 (Descriptor : in out Process_Descriptor;
361 Result : out Expect_Match;
362 Regexps : Regexp_Array;
363 Timeout : Integer := 10000;
364 Full_Buffer : Boolean := False)
366 Patterns : Compiled_Regexp_Array (Regexps'Range);
367 Matched : GNAT.Regpat.Match_Array (0 .. 0);
370 for J in Regexps'Range loop
371 Patterns (J) := new Pattern_Matcher'(Compile
(Regexps
(J
).all));
374 Expect
(Descriptor
, Result
, Patterns
, Matched
, Timeout
, Full_Buffer
);
376 for J
in Regexps
'Range loop
382 (Descriptor
: in out Process_Descriptor
;
383 Result
: out Expect_Match
;
384 Regexps
: Compiled_Regexp_Array
;
385 Timeout
: Integer := 10000;
386 Full_Buffer
: Boolean := False)
388 Matched
: GNAT
.Regpat
.Match_Array
(0 .. 0);
391 Expect
(Descriptor
, Result
, Regexps
, Matched
, Timeout
, Full_Buffer
);
395 (Result
: out Expect_Match
;
396 Regexps
: Multiprocess_Regexp_Array
;
397 Timeout
: Integer := 10000;
398 Full_Buffer
: Boolean := False)
400 Matched
: GNAT
.Regpat
.Match_Array
(0 .. 0);
403 Expect
(Result
, Regexps
, Matched
, Timeout
, Full_Buffer
);
407 (Descriptor
: in out Process_Descriptor
;
408 Result
: out Expect_Match
;
409 Regexps
: Regexp_Array
;
410 Matched
: out GNAT
.Regpat
.Match_Array
;
411 Timeout
: Integer := 10000;
412 Full_Buffer
: Boolean := False)
414 Patterns
: Compiled_Regexp_Array
(Regexps
'Range);
417 pragma Assert
(Matched
'First = 0);
419 for J
in Regexps
'Range loop
420 Patterns
(J
) := new Pattern_Matcher
'(Compile (Regexps (J).all));
423 Expect (Descriptor, Result, Patterns, Matched, Timeout, Full_Buffer);
425 for J in Regexps'Range loop
431 (Descriptor : in out Process_Descriptor;
432 Result : out Expect_Match;
433 Regexps : Compiled_Regexp_Array;
434 Matched : out GNAT.Regpat.Match_Array;
435 Timeout : Integer := 10000;
436 Full_Buffer : Boolean := False)
439 Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access);
442 pragma Assert (Matched'First = 0);
444 Reinitialize_Buffer (Descriptor);
447 -- First, test if what is already in the buffer matches (This is
448 -- required if this package is used in multi-task mode, since one of
449 -- the tasks might have added something in the buffer, and we don't
450 -- want other tasks to wait for new input to be available before
451 -- checking the regexps).
453 if Descriptor.Buffer /= null then
454 for J in Regexps'Range loop
457 Descriptor.Buffer (1 .. Descriptor.Buffer_Index),
460 if Matched (0) /= No_Match then
461 Result := Expect_Match (J);
462 Descriptor.Last_Match_Start := Matched (0).First;
463 Descriptor.Last_Match_End := Matched (0).Last;
469 Expect_Internal (Descriptors, N, Timeout, Full_Buffer);
471 if N = Expect_Timeout or else N = Expect_Full_Buffer then
479 (Result : out Expect_Match;
480 Regexps : Multiprocess_Regexp_Array;
481 Matched : out GNAT.Regpat.Match_Array;
482 Timeout : Integer := 10000;
483 Full_Buffer : Boolean := False)
486 Descriptors : Array_Of_Pd (Regexps'Range);
489 pragma Assert (Matched'First = 0);
491 for J in Descriptors'Range loop
492 Descriptors (J) := Regexps (J).Descriptor;
493 Reinitialize_Buffer (Regexps (J).Descriptor.all);
497 -- First, test if what is already in the buffer matches (This is
498 -- required if this package is used in multi-task mode, since one of
499 -- the tasks might have added something in the buffer, and we don't
500 -- want other tasks to wait for new input to be available before
501 -- checking the regexps).
503 for J in Regexps'Range loop
504 Match (Regexps (J).Regexp.all,
505 Regexps (J).Descriptor.Buffer
506 (1 .. Regexps (J).Descriptor.Buffer_Index),
509 if Matched (0) /= No_Match then
510 Result := Expect_Match (J);
511 Regexps (J).Descriptor.Last_Match_Start := Matched (0).First;
512 Regexps (J).Descriptor.Last_Match_End := Matched (0).Last;
517 Expect_Internal (Descriptors, N, Timeout, Full_Buffer);
519 if N = Expect_Timeout or else N = Expect_Full_Buffer then
526 ---------------------
527 -- Expect_Internal --
528 ---------------------
530 procedure Expect_Internal
531 (Descriptors : in out Array_Of_Pd;
532 Result : out Expect_Match;
534 Full_Buffer : Boolean)
536 Num_Descriptors : Integer;
537 Buffer_Size : Integer := 0;
541 type File_Descriptor_Array is
542 array (Descriptors'Range) of File_Descriptor;
543 Fds : aliased File_Descriptor_Array;
545 type Integer_Array is array (Descriptors'Range) of Integer;
546 Is_Set : aliased Integer_Array;
549 for J in Descriptors'Range loop
550 Fds (J) := Descriptors (J).Output_Fd;
552 if Descriptors (J).Buffer_Size = 0 then
553 Buffer_Size := Integer'Max (Buffer_Size, 4096);
556 Integer'Max (Buffer_Size, Descriptors (J).Buffer_Size);
561 Buffer : aliased String (1 .. Buffer_Size);
562 -- Buffer used for input. This is allocated only once, not for
563 -- every iteration of the loop
566 -- Loop until we match or we have a timeout
570 Poll (Fds'Address, Fds'Length, Timeout, Is_Set'Address);
572 case Num_Descriptors is
582 Result := Expect_Timeout;
588 for J in Descriptors'Range loop
589 if Is_Set (J) = 1 then
590 Buffer_Size := Descriptors (J).Buffer_Size;
592 if Buffer_Size = 0 then
596 N := Read (Descriptors (J).Output_Fd, Buffer'Address,
599 -- Error or End of file
602 -- ??? Note that ddd tries again up to three times
603 -- in that case. See LiterateA.C:174
607 -- If there is no limit to the buffer size
609 if Descriptors (J).Buffer_Size = 0 then
612 Tmp : String_Access := Descriptors (J).Buffer;
616 Descriptors (J).Buffer :=
617 new String (1 .. Tmp'Length + N);
618 Descriptors (J).Buffer (1 .. Tmp'Length) :=
620 Descriptors (J).Buffer
621 (Tmp'Length + 1 .. Tmp'Length + N) :=
624 Descriptors (J).Buffer_Index :=
625 Descriptors (J).Buffer'Last;
628 Descriptors (J).Buffer :=
630 Descriptors (J).Buffer.all :=
632 Descriptors (J).Buffer_Index := N;
637 -- Add what we read to the buffer
639 if Descriptors (J).Buffer_Index + N - 1 >
640 Descriptors (J).Buffer_Size
642 -- If the user wants to know when we have
643 -- read more than the buffer can contain.
646 Result := Expect_Full_Buffer;
650 -- Keep as much as possible from the buffer,
651 -- and forget old characters.
653 Descriptors (J).Buffer
654 (1 .. Descriptors (J).Buffer_Size - N) :=
655 Descriptors (J).Buffer
656 (N - Descriptors (J).Buffer_Size +
657 Descriptors (J).Buffer_Index + 1 ..
658 Descriptors (J).Buffer_Index);
659 Descriptors (J).Buffer_Index :=
660 Descriptors (J).Buffer_Size - N;
663 -- Keep what we read in the buffer.
665 Descriptors (J).Buffer
666 (Descriptors (J).Buffer_Index + 1 ..
667 Descriptors (J).Buffer_Index + N) :=
669 Descriptors (J).Buffer_Index :=
670 Descriptors (J).Buffer_Index + N;
673 -- Call each of the output filter with what we
677 (Descriptors (J).all, Buffer (1 .. N), Output);
679 Result := Expect_Match (N);
693 function Expect_Out (Descriptor : Process_Descriptor) return String is
695 return Descriptor.Buffer (1 .. Descriptor.Last_Match_End);
698 ----------------------
699 -- Expect_Out_Match --
700 ----------------------
702 function Expect_Out_Match (Descriptor : Process_Descriptor) return String is
704 return Descriptor.Buffer
705 (Descriptor.Last_Match_Start .. Descriptor.Last_Match_End);
706 end Expect_Out_Match;
713 (Descriptor : in out Process_Descriptor;
714 Timeout : Integer := 0)
716 Buffer_Size : constant Integer := 8192;
717 Num_Descriptors : Integer;
719 Is_Set : aliased Integer;
720 Buffer : aliased String (1 .. Buffer_Size);
723 -- Empty the current buffer
725 Descriptor.Last_Match_End := Descriptor.Buffer_Index;
726 Reinitialize_Buffer (Descriptor);
728 -- Read everything from the process to flush its output
732 Poll (Descriptor.Output_Fd'Address, 1, Timeout, Is_Set'Address);
734 case Num_Descriptors is
741 -- Timeout => End of flush
750 N := Read (Descriptor.Output_Fd, Buffer'Address,
768 function Get_Error_Fd
769 (Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor
772 return Descriptor.Error_Fd;
779 function Get_Input_Fd
780 (Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor
783 return Descriptor.Input_Fd;
790 function Get_Output_Fd
791 (Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor
794 return Descriptor.Output_Fd;
802 (Descriptor : Process_Descriptor) return Process_Id
805 return Descriptor.Pid;
812 procedure Interrupt (Descriptor : in out Process_Descriptor) is
813 SIGINT : constant := 2;
816 Send_Signal (Descriptor, SIGINT);
823 procedure Lock_Filters (Descriptor : in out Process_Descriptor) is
825 Descriptor.Filters_Lock := Descriptor.Filters_Lock + 1;
828 ------------------------
829 -- Non_Blocking_Spawn --
830 ------------------------
832 procedure Non_Blocking_Spawn
833 (Descriptor : out Process_Descriptor'Class;
835 Args : GNAT.OS_Lib.Argument_List;
836 Buffer_Size : Natural := 4096;
837 Err_To_Out : Boolean := False)
840 -------------------------
841 -- Reinitialize_Buffer --
842 -------------------------
844 procedure Reinitialize_Buffer
845 (Descriptor : in out Process_Descriptor'Class)
848 if Descriptor.Buffer_Size = 0 then
850 Tmp : String_Access := Descriptor.Buffer;
855 (1 .. Descriptor.Buffer_Index - Descriptor.Last_Match_End);
858 Descriptor.Buffer.all := Tmp
859 (Descriptor.Last_Match_End + 1 .. Descriptor.Buffer_Index);
864 Descriptor.Buffer_Index := Descriptor.Buffer'Last;
868 (1 .. Descriptor.Buffer_Index - Descriptor.Last_Match_End) :=
870 (Descriptor.Last_Match_End + 1 .. Descriptor.Buffer_Index);
872 if Descriptor.Buffer_Index > Descriptor.Last_Match_End then
873 Descriptor.Buffer_Index :=
874 Descriptor.Buffer_Index - Descriptor.Last_Match_End;
876 Descriptor.Buffer_Index := 0;
880 Descriptor.Last_Match_Start := 0;
881 Descriptor.Last_Match_End := 0;
882 end Reinitialize_Buffer;
888 procedure Remove_Filter
889 (Descriptor : in out Process_Descriptor;
890 Filter : Filter_Function)
892 Previous : Filter_List := null;
893 Current : Filter_List := Descriptor.Filters;
896 while Current /= null loop
897 if Current.Filter = Filter then
898 if Previous = null then
899 Descriptor.Filters := Current.Next;
901 Previous.Next := Current.Next;
906 Current := Current.Next;
915 (Descriptor : in out Process_Descriptor;
917 Add_LF : Boolean := True;
918 Empty_Buffer : Boolean := False)
920 Full_Str : constant String := Str & ASCII.LF;
922 Result : Expect_Match;
923 Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access);
926 pragma Unreferenced (Discard);
931 -- Force a read on the process if there is anything waiting
933 Expect_Internal (Descriptors, Result,
934 Timeout => 0, Full_Buffer => False);
935 Descriptor.Last_Match_End := Descriptor.Buffer_Index;
939 Reinitialize_Buffer (Descriptor);
943 Last := Full_Str'Last;
945 Last := Full_Str'Last - 1;
948 Call_Filters (Descriptor, Full_Str (Full_Str'First .. Last), Input);
950 Discard := Write (Descriptor.Input_Fd,
952 Last - Full_Str'First + 1);
953 -- Shouldn't we at least have a pragma Assert on the result ???
960 procedure Send_Signal
961 (Descriptor : Process_Descriptor;
965 Kill (Descriptor.Pid, Signal);
966 -- ??? Need to check process status here.
969 ---------------------------------
970 -- Set_Up_Child_Communications --
971 ---------------------------------
973 procedure Set_Up_Child_Communications
974 (Pid : in out Process_Descriptor;
975 Pipe1 : in out Pipe_Type;
976 Pipe2 : in out Pipe_Type;
977 Pipe3 : in out Pipe_Type;
979 Args : in System.Address)
981 pragma Warnings (Off, Pid);
984 -- Since the code between fork and exec on VMS executes
985 -- in the context of the parent process, we need to
986 -- perform the following actions:
987 -- - save stdin, stdout, stderr
988 -- - replace them by our pipes
989 -- - create the child with process handle inheritance
990 -- - revert to the previous stdin, stdout and stderr.
992 Save_Input := Dup (GNAT.OS_Lib.Standin);
993 Save_Output := Dup (GNAT.OS_Lib.Standout);
994 Save_Error := Dup (GNAT.OS_Lib.Standerr);
996 -- Since we are still called from the parent process, there is no way
997 -- currently we can cleanly close the unneeded ends of the pipes, but
998 -- this doesn't really matter.
999 -- We could close Pipe1.Output, Pipe2.Input, Pipe3.Input.
1001 Dup2 (Pipe1.Input, GNAT.OS_Lib.Standin);
1002 Dup2 (Pipe2.Output, GNAT.OS_Lib.Standout);
1003 Dup2 (Pipe3.Output, GNAT.OS_Lib.Standerr);
1005 Portable_Execvp (Pid.Pid'Access, Cmd & ASCII.Nul, Args);
1007 end Set_Up_Child_Communications;
1009 ---------------------------
1010 -- Set_Up_Communications --
1011 ---------------------------
1013 procedure Set_Up_Communications
1014 (Pid : in out Process_Descriptor;
1015 Err_To_Out : Boolean;
1016 Pipe1 : access Pipe_Type;
1017 Pipe2 : access Pipe_Type;
1018 Pipe3 : access Pipe_Type)
1023 if Create_Pipe (Pipe1) /= 0 then
1027 if Create_Pipe (Pipe2) /= 0 then
1031 Pid.Input_Fd := Pipe1.Output;
1032 Pid.Output_Fd := Pipe2.Input;
1035 Pipe3.all := Pipe2.all;
1037 if Create_Pipe (Pipe3) /= 0 then
1042 Pid.Error_Fd := Pipe3.Input;
1043 end Set_Up_Communications;
1045 ----------------------------------
1046 -- Set_Up_Parent_Communications --
1047 ----------------------------------
1049 procedure Set_Up_Parent_Communications
1050 (Pid : in out Process_Descriptor;
1051 Pipe1 : in out Pipe_Type;
1052 Pipe2 : in out Pipe_Type;
1053 Pipe3 : in out Pipe_Type)
1055 pragma Warnings (Off, Pid);
1059 Dup2 (Save_Input, GNAT.OS_Lib.Standin);
1060 Dup2 (Save_Output, GNAT.OS_Lib.Standout);
1061 Dup2 (Save_Error, GNAT.OS_Lib.Standerr);
1064 Close (Save_Output);
1067 Close (Pipe1.Input);
1068 Close (Pipe2.Output);
1069 Close (Pipe3.Output);
1070 end Set_Up_Parent_Communications;
1076 procedure Trace_Filter
1077 (Descriptor : Process_Descriptor'Class;
1079 User_Data : System.Address := System.Null_Address)
1081 pragma Warnings (Off, Descriptor);
1082 pragma Warnings (Off, User_Data);
1088 --------------------
1089 -- Unlock_Filters --
1090 --------------------
1092 procedure Unlock_Filters (Descriptor : in out Process_Descriptor) is
1094 if Descriptor.Filters_Lock > 0 then
1095 Descriptor.Filters_Lock := Descriptor.Filters_Lock - 1;