]> git.cameronkatri.com Git - bsd-progress.git/blobdiff - progress.c
updatre with latest from tzcode.
[bsd-progress.git] / progress.c
index bcec2eb7ec0f21bdfae8894a17c680f363e79d76..16886875f3fbf94d6632fafee5162c74607886ec 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: progress.c,v 1.16 2008/04/29 06:53:03 martin Exp $ */
+/*     $NetBSD: progress.c,v 1.21 2015/01/17 10:57:51 gson Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: progress.c,v 1.16 2008/04/29 06:53:03 martin Exp $");
+__RCSID("$NetBSD: progress.c,v 1.21 2015/01/17 10:57:51 gson Exp $");
 #endif                         /* not lint */
 
 #include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
 #include <sys/ioctl.h>
-#include <sys/time.h>
+#include <sys/stat.h>
 #include <sys/wait.h>
-#include <netinet/in.h>
-#include <arpa/ftp.h>
 
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <glob.h>
-#include <signal.h>
 #include <inttypes.h>
 #include <limits.h>
-#include <netdb.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <termios.h>
-#include <time.h>
-#include <tzfile.h>
 #include <unistd.h>
 
 #define GLOBAL                 /* force GLOBAL decls in progressbar.h to be
                                 * declared */
 #include "progressbar.h"
 
-static void usage(void);
-int main(int, char *[]);
+static void broken_pipe(int unused);
+__dead static void usage(void);
+
+static void
+broken_pipe(int unused)
+{
+       signal(SIGPIPE, SIG_DFL);
+       progressmeter(1);
+       kill(getpid(), SIGPIPE);
+}
 
 static void
 usage(void)
@@ -103,7 +102,7 @@ main(int argc, char *argv[])
                switch (ch) {
                case 'b':
                        buffersize = (size_t) strsuftoll("buffer size", optarg,
-                           0, SIZE_T_MAX);
+                           0, SSIZE_MAX);
                        break;
                case 'e':
                        eflag++;
@@ -226,13 +225,23 @@ main(int argc, char *argv[])
        }
        close(outpipe[0]);
 
+       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)
+                           (size_t) nr)) < 0) {
+                               progressmeter(1);
                                err(1, "writing %u bytes to output pipe",
                                                        (unsigned) nr);
+                       }
+       }
        close(outpipe[1]);
 
        gzipstat = 0;
@@ -263,6 +272,7 @@ main(int argc, char *argv[])
        }
 
        progressmeter(1);
+       signal(SIGPIPE, SIG_DFL);
 
        free(fb_buf);