]> git.cameronkatri.com Git - bsd-progress.git/blobdiff - progress.c
Sigh, use an even more elaborate wait loop; it turns out we have a child
[bsd-progress.git] / progress.c
index 05c8fdb999e10c80be5b4ede31dc4120cd1f28f3..d47e46e65feaba1d6d5470c2974b934b5734b81e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: progress.c,v 1.4 2003/01/22 04:11:34 jhawk Exp $ */
+/*     $NetBSD: progress.c,v 1.7 2003/02/12 00:58:34 ross Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: progress.c,v 1.4 2003/01/22 04:11:34 jhawk Exp $");
+__RCSID("$NetBSD: progress.c,v 1.7 2003/02/12 00:58:34 ross Exp $");
 #endif                         /* not lint */
 
 #include <sys/types.h>
@@ -84,7 +84,7 @@ main(int argc, char *argv[])
 {
        static char fb_buf[BUFSIZ];
        char *infile = NULL;
-       pid_t pid;
+       pid_t pid = 0, gzippid = 0;
        int ch, fd, outpipe[2], waitstat;
        int lflag = 0, zflag = 0;
        ssize_t nr, nw, off;
@@ -152,7 +152,6 @@ main(int argc, char *argv[])
        }
        /* Pipe input through gzip -dc if -z is given */
        if (zflag) {
-               pid_t gzippid;
                int gzippipe[2];
 
                if (pipe(gzippipe) < 0)
@@ -207,10 +206,25 @@ main(int argc, char *argv[])
                for (off = 0; nr; nr -= nw, off += nw, bytes += nw)
                        if ((nw = write(outpipe[1], fb_buf + off,
                            (size_t) nr)) < 0)
-                               err(1, "writing %d bytes to output pipe", nr);
+                               err(1, "writing %u bytes to output pipe",
+                                                       (unsigned) nr);
        close(outpipe[1]);
 
-       wait(&waitstat);
+       while (pid || gzippid) {
+               int deadpid;
+
+               deadpid = wait(&waitstat);
+
+               if (deadpid == pid)
+                       pid = 0;
+               else if (deadpid == gzippid)
+                       gzippid = 0;
+               else if (deadpid != -1)
+                       continue;
+               else if (errno == EINTR)
+                       continue;
+               else break;
+       }
 
        progressmeter(1);
        return 0;