1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- G N A T . E X P E C T --
10 -- Copyright (C) 2000-2002 Ada Core Technologies, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 ------------------------------------------------------------------------------
34 with System
; use System
;
35 with Ada
.Calendar
; use Ada
.Calendar
;
38 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
39 with GNAT
.Regpat
; use GNAT
.Regpat
;
41 with Unchecked_Deallocation
;
43 package body GNAT
.Expect
is
45 type Array_Of_Pd
is array (Positive range <>) of Process_Descriptor_Access
;
47 procedure Expect_Internal
48 (Descriptors
: in out Array_Of_Pd
;
49 Result
: out Expect_Match
;
51 Full_Buffer
: Boolean);
52 -- Internal function used to read from the process Descriptor.
54 -- Three outputs are possible:
55 -- Result=Expect_Timeout, if no output was available before the timeout
57 -- Result=Expect_Full_Buffer, if Full_Buffer is True and some characters
58 -- had to be discarded from the internal buffer of Descriptor.
59 -- Result=<integer>, indicates how many characters were added to the
60 -- internal buffer. These characters are from indexes
61 -- Descriptor.Buffer_Index - Result + 1 .. Descriptor.Buffer_Index
62 -- Process_Died is raised if the process is no longer valid.
64 procedure Reinitialize_Buffer
65 (Descriptor
: in out Process_Descriptor
'Class);
66 -- Reinitialize the internal buffer.
67 -- The buffer is deleted up to the end of the last match.
69 procedure Free
is new Unchecked_Deallocation
70 (Pattern_Matcher
, Pattern_Matcher_Access
);
72 procedure Call_Filters
73 (Pid
: Process_Descriptor
'Class;
75 Filter_On
: Filter_Type
);
76 -- Call all the filters that have the appropriate type.
77 -- This function does nothing if the filters are locked
79 ------------------------------
80 -- Target dependent section --
81 ------------------------------
83 function Dup
(Fd
: File_Descriptor
) return File_Descriptor
;
84 pragma Import
(C
, Dup
);
86 procedure Dup2
(Old_Fd
, New_Fd
: File_Descriptor
);
87 pragma Import
(C
, Dup2
);
89 procedure Kill
(Pid
: Process_Id
; Sig_Num
: Integer);
90 pragma Import
(C
, Kill
);
92 function Create_Pipe
(Pipe
: access Pipe_Type
) return Integer;
93 pragma Import
(C
, Create_Pipe
, "__gnat_pipe");
96 (Fd
: File_Descriptor
;
100 pragma Import
(C
, Read
, "read");
101 -- Read N bytes to address A from file referenced by FD. Returned value
102 -- is count of bytes actually read, which can be less than N at EOF.
104 procedure Close
(Fd
: File_Descriptor
);
105 pragma Import
(C
, Close
);
106 -- Close a file given its file descriptor.
109 (Fd
: File_Descriptor
;
113 pragma Import
(C
, Write
, "write");
114 -- Read N bytes to address A from file referenced by FD. Returned value
115 -- is count of bytes actually read, which can be less than N at EOF.
118 (Fds
: System
.Address
;
121 Is_Set
: System
.Address
) return Integer;
122 pragma Import
(C
, Poll
, "__gnat_expect_poll");
123 -- Check whether there is any data waiting on the file descriptor
124 -- Out_fd, and wait if there is none, at most Timeout milliseconds
125 -- Returns -1 in case of error, 0 if the timeout expired before
126 -- data became available.
128 -- Out_Is_Set is set to 1 if data was available, 0 otherwise.
130 function Waitpid
(Pid
: Process_Id
) return Integer;
131 pragma Import
(C
, Waitpid
, "__gnat_waitpid");
132 -- Wait for a specific process id, and return its exit code.
138 function "+" (S
: String) return GNAT
.OS_Lib
.String_Access
is
140 return new String'(S);
148 (P : GNAT.Regpat.Pattern_Matcher)
149 return Pattern_Matcher_Access
152 return new GNAT.Regpat.Pattern_Matcher'(P
);
160 (Descriptor
: in out Process_Descriptor
;
161 Filter
: Filter_Function
;
162 Filter_On
: Filter_Type
:= Output
;
163 User_Data
: System
.Address
:= System
.Null_Address
;
164 After
: Boolean := False)
166 Current
: Filter_List
:= Descriptor
.Filters
;
170 while Current
/= null and then Current
.Next
/= null loop
171 Current
:= Current
.Next
;
174 if Current
= null then
175 Descriptor
.Filters
:=
176 new Filter_List_Elem
'
177 (Filter => Filter, Filter_On => Filter_On,
178 User_Data => User_Data, Next => null);
181 new Filter_List_Elem'
182 (Filter
=> Filter
, Filter_On
=> Filter_On
,
183 User_Data
=> User_Data
, Next
=> null);
187 Descriptor
.Filters
:=
188 new Filter_List_Elem
'
189 (Filter => Filter, Filter_On => Filter_On,
190 User_Data => User_Data, Next => Descriptor.Filters);
198 procedure Call_Filters
199 (Pid : Process_Descriptor'Class;
201 Filter_On : Filter_Type)
203 Current_Filter : Filter_List;
206 if Pid.Filters_Lock = 0 then
207 Current_Filter := Pid.Filters;
209 while Current_Filter /= null loop
210 if Current_Filter.Filter_On = Filter_On then
211 Current_Filter.Filter
212 (Pid, Str, Current_Filter.User_Data);
215 Current_Filter := Current_Filter.Next;
225 (Descriptor : in out Process_Descriptor;
226 Status : out Integer)
229 Close (Descriptor.Input_Fd);
231 if Descriptor.Error_Fd /= Descriptor.Output_Fd then
232 Close (Descriptor.Error_Fd);
235 Close (Descriptor.Output_Fd);
237 -- ??? Should have timeouts for different signals
238 Kill (Descriptor.Pid, 9);
240 GNAT.OS_Lib.Free (Descriptor.Buffer);
241 Descriptor.Buffer_Size := 0;
243 Status := Waitpid (Descriptor.Pid);
246 procedure Close (Descriptor : in out Process_Descriptor) is
249 Close (Descriptor, Status);
257 (Descriptor : in out Process_Descriptor;
258 Result : out Expect_Match;
260 Timeout : Integer := 10000;
261 Full_Buffer : Boolean := False)
265 Expect (Descriptor, Result, Never_Match, Timeout, Full_Buffer);
267 Expect (Descriptor, Result, Compile (Regexp), Timeout, Full_Buffer);
272 (Descriptor : in out Process_Descriptor;
273 Result : out Expect_Match;
275 Matched : out GNAT.Regpat.Match_Array;
276 Timeout : Integer := 10000;
277 Full_Buffer : Boolean := False)
280 pragma Assert (Matched'First = 0);
283 (Descriptor, Result, Never_Match, Matched, Timeout, Full_Buffer);
286 (Descriptor, Result, Compile (Regexp), Matched, Timeout,
292 (Descriptor : in out Process_Descriptor;
293 Result : out Expect_Match;
294 Regexp : GNAT.Regpat.Pattern_Matcher;
295 Timeout : Integer := 10000;
296 Full_Buffer : Boolean := False)
298 Matched : GNAT.Regpat.Match_Array (0 .. 0);
301 Expect (Descriptor, Result, Regexp, Matched, Timeout, Full_Buffer);
305 (Descriptor : in out Process_Descriptor;
306 Result : out Expect_Match;
307 Regexp : GNAT.Regpat.Pattern_Matcher;
308 Matched : out GNAT.Regpat.Match_Array;
309 Timeout : Integer := 10000;
310 Full_Buffer : Boolean := False)
313 Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access);
314 Try_Until : Time := Clock + Duration (Timeout) / 1000.0;
315 Timeout_Tmp : Integer := Timeout;
318 pragma Assert (Matched'First = 0);
319 Reinitialize_Buffer (Descriptor);
322 -- First, test if what is already in the buffer matches (This is
323 -- required if this package is used in multi-task mode, since one of
324 -- the tasks might have added something in the buffer, and we don't
325 -- want other tasks to wait for new input to be available before
326 -- checking the regexps).
329 (Regexp, Descriptor.Buffer (1 .. Descriptor.Buffer_Index), Matched);
331 if Descriptor.Buffer_Index >= 1 and then Matched (0).First /= 0 then
333 Descriptor.Last_Match_Start := Matched (0).First;
334 Descriptor.Last_Match_End := Matched (0).Last;
338 -- Else try to read new input
340 Expect_Internal (Descriptors, N, Timeout_Tmp, Full_Buffer);
342 if N = Expect_Timeout or else N = Expect_Full_Buffer then
347 -- Calculate the timeout for the next turn.
348 -- Note that Timeout is, from the caller's perspective, the maximum
349 -- time until a match, not the maximum time until some output is
350 -- read, and thus can not be reused as is for Expect_Internal.
352 if Timeout /= -1 then
353 Timeout_Tmp := Integer (Try_Until - Clock) * 1000;
355 if Timeout_Tmp < 0 then
356 Result := Expect_Timeout;
362 -- Even if we had the general timeout above, we have to test that the
363 -- last test we read from the external process didn't match.
366 (Regexp, Descriptor.Buffer (1 .. Descriptor.Buffer_Index), Matched);
368 if Matched (0).First /= 0 then
370 Descriptor.Last_Match_Start := Matched (0).First;
371 Descriptor.Last_Match_End := Matched (0).Last;
377 (Descriptor : in out Process_Descriptor;
378 Result : out Expect_Match;
379 Regexps : Regexp_Array;
380 Timeout : Integer := 10000;
381 Full_Buffer : Boolean := False)
383 Patterns : Compiled_Regexp_Array (Regexps'Range);
384 Matched : GNAT.Regpat.Match_Array (0 .. 0);
387 for J in Regexps'Range loop
388 Patterns (J) := new Pattern_Matcher'(Compile
(Regexps
(J
).all));
391 Expect
(Descriptor
, Result
, Patterns
, Matched
, Timeout
, Full_Buffer
);
393 for J
in Regexps
'Range loop
399 (Descriptor
: in out Process_Descriptor
;
400 Result
: out Expect_Match
;
401 Regexps
: Compiled_Regexp_Array
;
402 Timeout
: Integer := 10000;
403 Full_Buffer
: Boolean := False)
405 Matched
: GNAT
.Regpat
.Match_Array
(0 .. 0);
408 Expect
(Descriptor
, Result
, Regexps
, Matched
, Timeout
, Full_Buffer
);
412 (Result
: out Expect_Match
;
413 Regexps
: Multiprocess_Regexp_Array
;
414 Timeout
: Integer := 10000;
415 Full_Buffer
: Boolean := False)
417 Matched
: GNAT
.Regpat
.Match_Array
(0 .. 0);
420 Expect
(Result
, Regexps
, Matched
, Timeout
, Full_Buffer
);
424 (Descriptor
: in out Process_Descriptor
;
425 Result
: out Expect_Match
;
426 Regexps
: Regexp_Array
;
427 Matched
: out GNAT
.Regpat
.Match_Array
;
428 Timeout
: Integer := 10000;
429 Full_Buffer
: Boolean := False)
431 Patterns
: Compiled_Regexp_Array
(Regexps
'Range);
434 pragma Assert
(Matched
'First = 0);
436 for J
in Regexps
'Range loop
437 Patterns
(J
) := new Pattern_Matcher
'(Compile (Regexps (J).all));
440 Expect (Descriptor, Result, Patterns, Matched, Timeout, Full_Buffer);
442 for J in Regexps'Range loop
448 (Descriptor : in out Process_Descriptor;
449 Result : out Expect_Match;
450 Regexps : Compiled_Regexp_Array;
451 Matched : out GNAT.Regpat.Match_Array;
452 Timeout : Integer := 10000;
453 Full_Buffer : Boolean := False)
456 Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access);
459 pragma Assert (Matched'First = 0);
461 Reinitialize_Buffer (Descriptor);
464 -- First, test if what is already in the buffer matches (This is
465 -- required if this package is used in multi-task mode, since one of
466 -- the tasks might have added something in the buffer, and we don't
467 -- want other tasks to wait for new input to be available before
468 -- checking the regexps).
470 if Descriptor.Buffer /= null then
471 for J in Regexps'Range loop
474 Descriptor.Buffer (1 .. Descriptor.Buffer_Index),
477 if Matched (0) /= No_Match then
478 Result := Expect_Match (J);
479 Descriptor.Last_Match_Start := Matched (0).First;
480 Descriptor.Last_Match_End := Matched (0).Last;
486 Expect_Internal (Descriptors, N, Timeout, Full_Buffer);
488 if N = Expect_Timeout or else N = Expect_Full_Buffer then
496 (Result : out Expect_Match;
497 Regexps : Multiprocess_Regexp_Array;
498 Matched : out GNAT.Regpat.Match_Array;
499 Timeout : Integer := 10000;
500 Full_Buffer : Boolean := False)
503 Descriptors : Array_Of_Pd (Regexps'Range);
506 pragma Assert (Matched'First = 0);
508 for J in Descriptors'Range loop
509 Descriptors (J) := Regexps (J).Descriptor;
510 Reinitialize_Buffer (Regexps (J).Descriptor.all);
514 -- First, test if what is already in the buffer matches (This is
515 -- required if this package is used in multi-task mode, since one of
516 -- the tasks might have added something in the buffer, and we don't
517 -- want other tasks to wait for new input to be available before
518 -- checking the regexps).
520 for J in Regexps'Range loop
521 Match (Regexps (J).Regexp.all,
522 Regexps (J).Descriptor.Buffer
523 (1 .. Regexps (J).Descriptor.Buffer_Index),
526 if Matched (0) /= No_Match then
527 Result := Expect_Match (J);
528 Regexps (J).Descriptor.Last_Match_Start := Matched (0).First;
529 Regexps (J).Descriptor.Last_Match_End := Matched (0).Last;
534 Expect_Internal (Descriptors, N, Timeout, Full_Buffer);
536 if N = Expect_Timeout or else N = Expect_Full_Buffer then
543 ---------------------
544 -- Expect_Internal --
545 ---------------------
547 procedure Expect_Internal
548 (Descriptors : in out Array_Of_Pd;
549 Result : out Expect_Match;
551 Full_Buffer : Boolean)
553 Num_Descriptors : Integer;
554 Buffer_Size : Integer := 0;
558 type File_Descriptor_Array is
559 array (Descriptors'Range) of File_Descriptor;
560 Fds : aliased File_Descriptor_Array;
562 type Integer_Array is array (Descriptors'Range) of Integer;
563 Is_Set : aliased Integer_Array;
566 for J in Descriptors'Range loop
567 Fds (J) := Descriptors (J).Output_Fd;
569 if Descriptors (J).Buffer_Size = 0 then
570 Buffer_Size := Integer'Max (Buffer_Size, 4096);
573 Integer'Max (Buffer_Size, Descriptors (J).Buffer_Size);
578 Buffer : aliased String (1 .. Buffer_Size);
579 -- Buffer used for input. This is allocated only once, not for
580 -- every iteration of the loop
583 -- Loop until we match or we have a timeout
587 Poll (Fds'Address, Fds'Length, Timeout, Is_Set'Address);
589 case Num_Descriptors is
599 Result := Expect_Timeout;
605 for J in Descriptors'Range loop
606 if Is_Set (J) = 1 then
607 Buffer_Size := Descriptors (J).Buffer_Size;
609 if Buffer_Size = 0 then
613 N := Read (Descriptors (J).Output_Fd, Buffer'Address,
616 -- Error or End of file
619 -- ??? Note that ddd tries again up to three times
620 -- in that case. See LiterateA.C:174
624 -- If there is no limit to the buffer size
626 if Descriptors (J).Buffer_Size = 0 then
629 Tmp : String_Access := Descriptors (J).Buffer;
633 Descriptors (J).Buffer :=
634 new String (1 .. Tmp'Length + N);
635 Descriptors (J).Buffer (1 .. Tmp'Length) :=
637 Descriptors (J).Buffer
638 (Tmp'Length + 1 .. Tmp'Length + N) :=
641 Descriptors (J).Buffer_Index :=
642 Descriptors (J).Buffer'Last;
645 Descriptors (J).Buffer :=
647 Descriptors (J).Buffer.all :=
649 Descriptors (J).Buffer_Index := N;
654 -- Add what we read to the buffer
656 if Descriptors (J).Buffer_Index + N - 1 >
657 Descriptors (J).Buffer_Size
659 -- If the user wants to know when we have
660 -- read more than the buffer can contain.
663 Result := Expect_Full_Buffer;
667 -- Keep as much as possible from the buffer,
668 -- and forget old characters.
670 Descriptors (J).Buffer
671 (1 .. Descriptors (J).Buffer_Size - N) :=
672 Descriptors (J).Buffer
673 (N - Descriptors (J).Buffer_Size +
674 Descriptors (J).Buffer_Index + 1 ..
675 Descriptors (J).Buffer_Index);
676 Descriptors (J).Buffer_Index :=
677 Descriptors (J).Buffer_Size - N;
680 -- Keep what we read in the buffer.
682 Descriptors (J).Buffer
683 (Descriptors (J).Buffer_Index + 1 ..
684 Descriptors (J).Buffer_Index + N) :=
686 Descriptors (J).Buffer_Index :=
687 Descriptors (J).Buffer_Index + N;
690 -- Call each of the output filter with what we
694 (Descriptors (J).all, Buffer (1 .. N), Output);
696 Result := Expect_Match (N);
710 function Expect_Out (Descriptor : Process_Descriptor) return String is
712 return Descriptor.Buffer (1 .. Descriptor.Last_Match_End);
715 ----------------------
716 -- Expect_Out_Match --
717 ----------------------
719 function Expect_Out_Match (Descriptor : Process_Descriptor) return String is
721 return Descriptor.Buffer
722 (Descriptor.Last_Match_Start .. Descriptor.Last_Match_End);
723 end Expect_Out_Match;
730 (Descriptor : in out Process_Descriptor;
731 Timeout : Integer := 0)
733 Num_Descriptors : Integer;
735 Is_Set : aliased Integer;
736 Buffer_Size : Integer := 8192;
737 Buffer : aliased String (1 .. Buffer_Size);
740 -- Empty the current buffer
742 Descriptor.Last_Match_End := Descriptor.Buffer_Index;
743 Reinitialize_Buffer (Descriptor);
745 -- Read everything from the process to flush its output
749 Poll (Descriptor.Output_Fd'Address, 1, Timeout, Is_Set'Address);
751 case Num_Descriptors is
758 -- Timeout => End of flush
767 N := Read (Descriptor.Output_Fd, Buffer'Address,
785 function Get_Error_Fd
786 (Descriptor : Process_Descriptor)
787 return GNAT.OS_Lib.File_Descriptor
790 return Descriptor.Error_Fd;
797 function Get_Input_Fd
798 (Descriptor : Process_Descriptor)
799 return GNAT.OS_Lib.File_Descriptor
802 return Descriptor.Input_Fd;
809 function Get_Output_Fd
810 (Descriptor : Process_Descriptor)
811 return GNAT.OS_Lib.File_Descriptor
814 return Descriptor.Output_Fd;
822 (Descriptor : Process_Descriptor)
826 return Descriptor.Pid;
833 procedure Interrupt (Descriptor : in out Process_Descriptor) is
834 SIGINT : constant := 2;
837 Send_Signal (Descriptor, SIGINT);
844 procedure Lock_Filters (Descriptor : in out Process_Descriptor) is
846 Descriptor.Filters_Lock := Descriptor.Filters_Lock + 1;
849 ------------------------
850 -- Non_Blocking_Spawn --
851 ------------------------
853 procedure Non_Blocking_Spawn
854 (Descriptor : out Process_Descriptor'Class;
856 Args : GNAT.OS_Lib.Argument_List;
857 Buffer_Size : Natural := 4096;
858 Err_To_Out : Boolean := False)
862 -------------------------
863 -- Reinitialize_Buffer --
864 -------------------------
866 procedure Reinitialize_Buffer
867 (Descriptor : in out Process_Descriptor'Class)
870 if Descriptor.Buffer_Size = 0 then
872 Tmp : String_Access := Descriptor.Buffer;
877 (1 .. Descriptor.Buffer_Index - Descriptor.Last_Match_End);
880 Descriptor.Buffer.all := Tmp
881 (Descriptor.Last_Match_End + 1 .. Descriptor.Buffer_Index);
886 Descriptor.Buffer_Index := Descriptor.Buffer'Last;
890 (1 .. Descriptor.Buffer_Index - Descriptor.Last_Match_End) :=
892 (Descriptor.Last_Match_End + 1 .. Descriptor.Buffer_Index);
894 if Descriptor.Buffer_Index > Descriptor.Last_Match_End then
895 Descriptor.Buffer_Index :=
896 Descriptor.Buffer_Index - Descriptor.Last_Match_End;
898 Descriptor.Buffer_Index := 0;
902 Descriptor.Last_Match_Start := 0;
903 Descriptor.Last_Match_End := 0;
904 end Reinitialize_Buffer;
910 procedure Remove_Filter
911 (Descriptor : in out Process_Descriptor;
912 Filter : Filter_Function)
914 Previous : Filter_List := null;
915 Current : Filter_List := Descriptor.Filters;
918 while Current /= null loop
919 if Current.Filter = Filter then
920 if Previous = null then
921 Descriptor.Filters := Current.Next;
923 Previous.Next := Current.Next;
928 Current := Current.Next;
937 (Descriptor : in out Process_Descriptor;
939 Add_LF : Boolean := True;
940 Empty_Buffer : Boolean := False)
943 Full_Str : constant String := Str & ASCII.LF;
945 Result : Expect_Match;
946 Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access);
951 -- Force a read on the process if there is anything waiting.
953 Expect_Internal (Descriptors, Result,
954 Timeout => 0, Full_Buffer => False);
955 Descriptor.Last_Match_End := Descriptor.Buffer_Index;
959 Reinitialize_Buffer (Descriptor);
963 Last := Full_Str'Last;
965 Last := Full_Str'Last - 1;
968 Call_Filters (Descriptor, Full_Str (Full_Str'First .. Last), Input);
970 N := Write (Descriptor.Input_Fd,
972 Last - Full_Str'First + 1);
979 procedure Send_Signal
980 (Descriptor : Process_Descriptor;
984 Kill (Descriptor.Pid, Signal);
985 -- ??? Need to check process status here.
988 ---------------------------------
989 -- Set_Up_Child_Communications --
990 ---------------------------------
992 procedure Set_Up_Child_Communications
993 (Pid : in out Process_Descriptor;
994 Pipe1 : in out Pipe_Type;
995 Pipe2 : in out Pipe_Type;
996 Pipe3 : in out Pipe_Type;
998 Args : in System.Address)
1000 pragma Warnings (Off, Pid);
1002 Input : File_Descriptor;
1003 Output : File_Descriptor;
1004 Error : File_Descriptor;
1007 -- Since Windows does not have a separate fork/exec, we need to
1008 -- perform the following actions:
1009 -- - save stdin, stdout, stderr
1010 -- - replace them by our pipes
1011 -- - create the child with process handle inheritance
1012 -- - revert to the previous stdin, stdout and stderr.
1014 Input := Dup (GNAT.OS_Lib.Standin);
1015 Output := Dup (GNAT.OS_Lib.Standout);
1016 Error := Dup (GNAT.OS_Lib.Standerr);
1018 -- Since we are still called from the parent process, there is no way
1019 -- currently we can cleanly close the unneeded ends of the pipes, but
1020 -- this doesn't really matter.
1021 -- We could close Pipe1.Output, Pipe2.Input, Pipe3.Input.
1023 Dup2 (Pipe1.Input, GNAT.OS_Lib.Standin);
1024 Dup2 (Pipe2.Output, GNAT.OS_Lib.Standout);
1025 Dup2 (Pipe3.Output, GNAT.OS_Lib.Standerr);
1027 Portable_Execvp (Pid.Pid'Access, Cmd & ASCII.Nul, Args);
1029 -- The following commands are not executed on Unix systems, and are
1030 -- only required for Windows systems. We are now in the parent process.
1032 -- Restore the old descriptors
1034 Dup2 (Input, GNAT.OS_Lib.Standin);
1035 Dup2 (Output, GNAT.OS_Lib.Standout);
1036 Dup2 (Error, GNAT.OS_Lib.Standerr);
1040 end Set_Up_Child_Communications;
1042 ---------------------------
1043 -- Set_Up_Communications --
1044 ---------------------------
1046 procedure Set_Up_Communications
1047 (Pid : in out Process_Descriptor;
1048 Err_To_Out : Boolean;
1049 Pipe1 : access Pipe_Type;
1050 Pipe2 : access Pipe_Type;
1051 Pipe3 : access Pipe_Type)
1056 if Create_Pipe (Pipe1) /= 0 then
1060 if Create_Pipe (Pipe2) /= 0 then
1064 Pid.Input_Fd := Pipe1.Output;
1065 Pid.Output_Fd := Pipe2.Input;
1068 Pipe3.all := Pipe2.all;
1070 if Create_Pipe (Pipe3) /= 0 then
1075 Pid.Error_Fd := Pipe3.Input;
1076 end Set_Up_Communications;
1078 ----------------------------------
1079 -- Set_Up_Parent_Communications --
1080 ----------------------------------
1082 procedure Set_Up_Parent_Communications
1083 (Pid : in out Process_Descriptor;
1084 Pipe1 : in out Pipe_Type;
1085 Pipe2 : in out Pipe_Type;
1086 Pipe3 : in out Pipe_Type)
1088 pragma Warnings (Off, Pid);
1091 Close (Pipe1.Input);
1092 Close (Pipe2.Output);
1093 Close (Pipe3.Output);
1094 end Set_Up_Parent_Communications;
1100 procedure Trace_Filter
1101 (Descriptor : Process_Descriptor'Class;
1103 User_Data : System.Address := System.Null_Address)
1105 pragma Warnings (Off, Descriptor);
1106 pragma Warnings (Off, User_Data);
1112 --------------------
1113 -- Unlock_Filters --
1114 --------------------
1116 procedure Unlock_Filters (Descriptor : in out Process_Descriptor) is
1118 if Descriptor.Filters_Lock > 0 then
1119 Descriptor.Filters_Lock := Descriptor.Filters_Lock - 1;