]> git.cameronkatri.com Git - bsd-progress.git/commitdiff
Retry read() on EINTR. Fixes premature exit of
authorgson <gson@NetBSD.org>
Sat, 17 Jan 2015 10:57:51 +0000 (10:57 +0000)
committergson <gson@NetBSD.org>
Sat, 17 Jan 2015 10:57:51 +0000 (10:57 +0000)
</dev/random progress -e cat >/dev/null

progress.c

index e6499899dcd6d2c22e7e964193dc03ffc8d44b50..16886875f3fbf94d6632fafee5162c74607886ec 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: progress.c,v 1.20 2012/06/27 22:07:36 riastradh Exp $ */
+/*     $NetBSD: progress.c,v 1.21 2015/01/17 10:57:51 gson Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: progress.c,v 1.20 2012/06/27 22:07:36 riastradh Exp $");
+__RCSID("$NetBSD: progress.c,v 1.21 2015/01/17 10:57:51 gson Exp $");
 #endif                         /* not lint */
 
 #include <sys/types.h>
@@ -228,7 +228,12 @@ main(int argc, char *argv[])
        signal(SIGPIPE, broken_pipe);
        progressmeter(-1);
 
-       while ((nr = read(fd, fb_buf, buffersize)) > 0)
+       while (1) {
+               do {
+                       nr = read(fd, fb_buf, buffersize);
+               } while (nr < 0 && errno == EINTR);
+               if (nr <= 0)
+                       break;
                for (off = 0; nr; nr -= nw, off += nw, bytes += nw)
                        if ((nw = write(outpipe[1], fb_buf + off,
                            (size_t) nr)) < 0) {
@@ -236,6 +241,7 @@ main(int argc, char *argv[])
                                err(1, "writing %u bytes to output pipe",
                                                        (unsigned) nr);
                        }
+       }
        close(outpipe[1]);
 
        gzipstat = 0;