1 Blake sent me the wrong one
.
3 /* RCS $Id: runargv.c,v 1.2 2007-10-15 16:00:01 ihi Exp $
6 -- Invoke a sub process.
9 -- Use the standard methods of executing a sub process.
12 -- Dennis Vadura, dvadura@dmake.wticorp.com
15 -- http://dmake.wticorp.com/
18 -- Copyright (c) 1996,1997 by WTI Corp. All rights reserved.
20 -- This program is NOT free software; you can redistribute it and/or
21 -- modify it under the terms of the Software License Agreement Provided
22 -- in the file <distribution-root>/readme/license.txt.
25 -- Use cvs log to obtain detailed change logs.
34 extern char **environ
;
56 static PR
*_procs
= NIL(PR
);
57 static int _proc_cnt
= 0;
58 static int _abort_flg
= FALSE
;
59 static int _use_i
= -1;
60 static int _do_upd
= 0;
62 static void _add_child
ANSI((int, CELLPTR
, int, int));
63 static void _attach_cmd
ANSI((char *, int, int, CELLPTR
, int, int));
64 static void _finished_child
ANSI((int, int));
65 static int _running
ANSI((CELLPTR
));
68 runargv(target
, ignore
, group
, last
, shell
, cmd
)
77 extern char *sys_errlist
[];
81 if( _running(target
) /*&& Max_proc != 1*/ ) {
82 /* The command will be executed when the previous recipe
84 _attach_cmd( cmd
, group
, ignore
, target
, last
, shell
);
88 while( _proc_cnt
== Max_proc
)
89 if( Wait_for_child(FALSE
, -1) == -1 ) Fatal( "Lost a child %d", errno
);
91 argv
= Pack_argv( group
, shell
, cmd
);
93 pid
= _spawnvpe(_P_NOWAIT
, argv
[0], argv
, environ
);
94 if (pid
== -1) { /* failed */
95 Error("%s: %s", argv
[0], sys_errlist
[errno
]);
96 Handle_result(-1, ignore
, _abort_flg
, target
);
99 _add_child(pid
, target
, ignore
, last
);
106 Wait_for_child( abort_flg
, pid
)
114 waitchild
= (pid
== -1)? FALSE
: Wait_for_completion
;
117 if( (wid
= wait(&status
)) == -1 ) return(-1);
119 _abort_flg
= abort_flg
;
120 _finished_child(wid
, status
);
122 } while( waitchild
&& pid
!= wid
);
133 if( _procs
!= NIL(PR
) ) {
134 for( i
=0; i
<Max_proc
; i
++ )
135 if( _procs
[i
].pr_valid
)
136 kill(_procs
[i
].pr_pid
, SIGTERM
);
138 while( Wait_for_child(TRUE
, -1) != -1 );
144 _add_child( pid
, target
, ignore
, last
)
153 if( _procs
== NIL(PR
) ) {
154 TALLOC( _procs
, Max_proc
, PR
);
157 if( (i
= _use_i
) == -1 )
158 for( i
=0; i
<Max_proc
; i
++ )
159 if( !_procs
[i
].pr_valid
)
166 pp
->pr_target
= target
;
167 pp
->pr_ignore
= ignore
;
169 pp
->pr_dir
= DmStrDup(Get_current_dir());
171 Current_target
= NIL(CELL
);
175 if( Wait_for_completion
) Wait_for_child( FALSE
, pid
);
180 _finished_child(pid
, status
)
188 for( i
=0; i
<Max_proc
; i
++ )
189 if( _procs
[i
].pr_valid
&& _procs
[i
].pr_pid
== pid
)
192 /* Some children we didn't make esp true if using /bin/sh to execute a
193 * a pipe and feed the output as a makefile into dmake. */
194 if( i
== Max_proc
) return;
195 _procs
[i
].pr_valid
= 0;
197 dir
= DmStrDup(Get_current_dir());
198 Set_dir( _procs
[i
].pr_dir
);
200 if( _procs
[i
].pr_recipe
!= NIL(RCP
) && !_abort_flg
) {
201 RCPPTR rp
= _procs
[i
].pr_recipe
;
204 Current_target
= _procs
[i
].pr_target
;
205 Handle_result( status
, _procs
[i
].pr_ignore
, FALSE
, _procs
[i
].pr_target
);
206 Current_target
= NIL(CELL
);
208 if ( _procs
[i
].pr_target
->ce_attr
& A_ERROR
) {
209 _procs
[i
].pr_last
= TRUE
;
210 goto ABORT_REMAINDER_OF_RECIPE
;
213 _procs
[i
].pr_recipe
= rp
->prp_next
;
216 runargv( _procs
[i
].pr_target
, rp
->prp_ignore
, rp
->prp_group
,
217 rp
->prp_last
, rp
->prp_shell
, rp
->prp_cmd
);
223 if( _proc_cnt
== Max_proc
) Wait_for_child( FALSE
, -1 );
226 Handle_result(status
,_procs
[i
].pr_ignore
,_abort_flg
,_procs
[i
].pr_target
);
228 ABORT_REMAINDER_OF_RECIPE
:
229 if( _procs
[i
].pr_last
) {
230 FREE(_procs
[i
].pr_dir
);
232 if( !Doing_bang
) Update_time_stamp( _procs
[i
].pr_target
);
247 if( !_procs
) return(FALSE
);
249 for( i
=0; i
<Max_proc
; i
++ )
250 if( _procs
[i
].pr_valid
&&
251 _procs
[i
].pr_target
== cp
)
254 return( i
!= Max_proc
);
259 _attach_cmd( cmd
, group
, ignore
, cp
, last
, shell
)
270 for( i
=0; i
<Max_proc
; i
++ )
271 if( _procs
[i
].pr_valid
&&
272 _procs
[i
].pr_target
== cp
)
275 TALLOC( rp
, 1, RCP
);
276 rp
->prp_cmd
= DmStrDup(cmd
);
277 rp
->prp_group
= group
;
278 rp
->prp_ignore
= ignore
;
280 rp
->prp_shell
= shell
;
282 if( _procs
[i
].pr_recipe
== NIL(RCP
) )
283 _procs
[i
].pr_recipe
= _procs
[i
].pr_recipe_end
= rp
;
285 _procs
[i
].pr_recipe_end
->prp_next
= rp
;
286 _procs
[i
].pr_recipe_end
= rp
;