]> git.cameronkatri.com Git - bsd-progress.git/commitdiff
Cosmetic fix: don't exit without completing the progress bar, either on
authordholland <dholland@NetBSD.org>
Mon, 26 May 2008 04:53:11 +0000 (04:53 +0000)
committerdholland <dholland@NetBSD.org>
Mon, 26 May 2008 04:53:11 +0000 (04:53 +0000)
write error or by receiving SIGPIPE. This avoids leaving the tty in a
mess. Probably addresses PR 30287.

progress.c

index bcec2eb7ec0f21bdfae8894a17c680f363e79d76..826d240dda2f4f688514e7f56cacdf62ecc8ba1f 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.17 2008/05/26 04:53:11 dholland Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #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.17 2008/05/26 04:53:11 dholland Exp $");
 #endif                         /* not lint */
 
 #include <sys/types.h>
@@ -63,9 +63,18 @@ __RCSID("$NetBSD: progress.c,v 1.16 2008/04/29 06:53:03 martin Exp $");
                                 * declared */
 #include "progressbar.h"
 
+static void broken_pipe(int unused);
 static void usage(void);
 int main(int, char *[]);
 
+static void
+broken_pipe(int unused)
+{
+       signal(SIGPIPE, SIG_DFL);
+       progressmeter(1);
+       kill(getpid(), SIGPIPE);
+}
+
 static void
 usage(void)
 {
@@ -226,13 +235,17 @@ main(int argc, char *argv[])
        }
        close(outpipe[0]);
 
+       signal(SIGPIPE, broken_pipe);
        progressmeter(-1);
+
        while ((nr = read(fd, fb_buf, buffersize)) > 0)
                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 +276,7 @@ main(int argc, char *argv[])
        }
 
        progressmeter(1);
+       signal(SIGPIPE, SIG_DFL);
 
        free(fb_buf);