aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2008-05-26 04:53:11 +0000
committerdholland <dholland@NetBSD.org>2008-05-26 04:53:11 +0000
commitc9d7b94ae449056c85da41a3504e7e612a037f19 (patch)
tree786e5e31f194e3e12d420ebc52e9e92e353b88ac
parent22ab394e4d844d46ee5ea0cf7a8e44e89056296d (diff)
downloadbsd-progress-c9d7b94ae449056c85da41a3504e7e612a037f19.tar.gz
bsd-progress-c9d7b94ae449056c85da41a3504e7e612a037f19.tar.zst
bsd-progress-c9d7b94ae449056c85da41a3504e7e612a037f19.zip
Cosmetic fix: don't exit without completing the progress bar, either on
write error or by receiving SIGPIPE. This avoids leaving the tty in a mess. Probably addresses PR 30287.
-rw-r--r--progress.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/progress.c b/progress.c
index bcec2eb..826d240 100644
--- a/progress.c
+++ b/progress.c
@@ -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,10 +63,19 @@ __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)
{
fprintf(stderr,
@@ -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);