2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
15 static char rcs_id[] = "$Id: run.c,v 2.9 1994/06/24 10:13:06 ceriel Exp $" ;
18 #define ARG_MORE 40 /* The size of args chunks to allocate */
20 extern growstring scanvars();
22 static char **arglist ; /* The first argument */
23 static unsigned argcount ; /* The current number of arguments */
24 static unsigned argmax; /* The maximum number of arguments so far */
26 int runphase(phase) register trf *phase ; {
27 register list_elem *elem ;
28 char *prog ; int result ;
31 bline=scanvars(phase->t_prog) ;
32 prog=gr_final(&bline) ;
33 if ( v_flag || debug ) {
34 if ( v_flag==1 && !debug ) {
35 vprint("%s",phase->t_name) ;
36 if ( !phase->t_combine ) {
37 vprint(" %s%s\n",p_basename,
38 strrindex(in.p_path,SUFCHAR) ) ;
40 scanlist(l_first(phase->t_inputs), elem) {
41 vprint(" %s",p_cont(*elem)->p_path);
48 scanlist(l_first(phase->t_flags), elem) {
49 vprint(" %s",l_content(*elem)) ;
51 scanlist(l_first(phase->t_args), elem) {
52 vprint(" %s",l_content(*elem)) ;
58 x_arg(phase->t_name) ;
59 scanlist(l_first(phase->t_flags), elem) {
60 x_arg(l_content(*elem)) ;
62 scanlist(l_first(phase->t_args), elem) {
63 x_arg(l_content(*elem)) ;
66 result=run_exec(phase,prog) ;
71 int run_exec(phase,prog) trf *phase ; char *prog ; {
72 int status, child, waitchild ;
75 while ( (child=fork())== -1 ) ;
79 waitchild= wait(&status) ;
80 if ( waitchild== -1 ) {
81 fatal("missing child") ;
83 } while ( waitchild!=child) ;
85 if ( status&0200 && (status&0177)!=SIGQUIT &&
86 t_flag<=1 ) unlink("core") ;
87 switch ( status&0177 ) {
96 error("%s died with signal %d",
99 /* The assumption is that processes voluntarely
100 dying with a non-zero status already produced
101 some sort of error message to the outside world.
106 return 1 ; /* From the parent */
109 if ( phase->t_stdin ) {
111 fatal("no input file for %s",phase->t_name) ;
114 if ( open(in.p_path,0)!=0 ) {
115 error("cannot open %s",in.p_path) ;
119 if ( phase->t_stdout ) {
121 fatal("no output file for %s",phase->t_name) ;
124 if ( creat(out.p_path,0666)!=1 ) {
126 error("cannot create %s",out.p_path) ;
130 execv(prog,arglist) ;
131 if ( phase->t_stdout ) { close(1) ; dup(2) ; }
132 error("Cannot execute %s",prog) ;
137 x_arg(string) char *string ; {
138 /* Add one execute argument to the argument vector */
139 if ( argcount==argmax ) {
142 arglist= (char **)getcore(argmax*sizeof (char *)) ;
145 arglist= (char **)changecore((char *)arglist,
146 argmax*sizeof (char *)) ;
149 *(arglist+argcount++) = string ;