do a pclose on pipes to wait for child.
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Wed, 5 Dec 1984 01:42:23 +0000 (17:42 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Wed, 5 Dec 1984 01:42:23 +0000 (17:42 -0800)
SCCS-vsn: old/awk/run.c 4.5

usr/src/old/awk/run.c

index 1a8141b..7486a73 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)run.c      4.4 %G%";
+static char sccsid[] = "@(#)run.c      4.5 %G%";
 #endif
 
 #include "awk.def"
 #endif
 
 #include "awk.def"
@@ -12,6 +12,7 @@ static char sccsid[] = "@(#)run.c     4.4 %G%";
 struct
 {
        FILE *fp;
 struct
 {
        FILE *fp;
+       int type;
        char *fname;
 } files[FILENUM];
 FILE *popen();
        char *fname;
 } files[FILENUM];
 FILE *popen();
@@ -28,7 +29,14 @@ obj  false   ={ OBOOL, BFALSE, 0 };
 
 run()
 {
 
 run()
 {
+       register int i;
+
        execute(winner);
        execute(winner);
+
+       /* Wait for children to complete if output to a pipe. */
+       for (i=0; i<FILENUM; i++)
+               if (files[i].fp && files[i].type == '|')
+                       pclose(files[i].fp);
 }
 
 obj execute(u) node *u;
 }
 
 obj execute(u) node *u;
@@ -866,6 +874,7 @@ redirprint(s, a, b) char *s; node *b;
        if (files[i].fp == NULL)
                error(FATAL, "can't open file %s", x.optr->sval);
        files[i].fname = tostring(x.optr->sval);
        if (files[i].fp == NULL)
                error(FATAL, "can't open file %s", x.optr->sval);
        files[i].fname = tostring(x.optr->sval);
+       files[i].type = a;
 doit:
        fprintf(files[i].fp, "%s", s);
 #ifndef gcos
 doit:
        fprintf(files[i].fp, "%s", s);
 #ifndef gcos