Fri Jan 29 18:27:05 2021 UTC ()
Pull up following revision(s) (requested by lukem in ticket #1189):

	usr.bin/progress/progress.c: revision 1.23

progress: handle EINTR in writes. PR/55914


(martin)
diff -r1.21 -r1.21.18.1 src/usr.bin/progress/progress.c

cvs diff -r1.21 -r1.21.18.1 src/usr.bin/progress/progress.c (expand / switch to unified diff)

--- src/usr.bin/progress/progress.c 2015/01/17 10:57:51 1.21
+++ src/usr.bin/progress/progress.c 2021/01/29 18:27:05 1.21.18.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: progress.c,v 1.21 2015/01/17 10:57:51 gson Exp $ */ 1/* $NetBSD: progress.c,v 1.21.18.1 2021/01/29 18:27:05 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by John Hawkinson. 8 * by John Hawkinson.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34__RCSID("$NetBSD: progress.c,v 1.21 2015/01/17 10:57:51 gson Exp $"); 34__RCSID("$NetBSD: progress.c,v 1.21.18.1 2021/01/29 18:27:05 martin Exp $");
35#endif /* not lint */ 35#endif /* not lint */
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/ioctl.h> 38#include <sys/ioctl.h>
39#include <sys/stat.h> 39#include <sys/stat.h>
40#include <sys/wait.h> 40#include <sys/wait.h>
41 41
42#include <err.h> 42#include <err.h>
43#include <errno.h> 43#include <errno.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <inttypes.h> 45#include <inttypes.h>
46#include <limits.h> 46#include <limits.h>
47#include <signal.h> 47#include <signal.h>
@@ -227,26 +227,30 @@ main(int argc, char *argv[]) @@ -227,26 +227,30 @@ main(int argc, char *argv[])
227 227
228 signal(SIGPIPE, broken_pipe); 228 signal(SIGPIPE, broken_pipe);
229 progressmeter(-1); 229 progressmeter(-1);
230 230
231 while (1) { 231 while (1) {
232 do { 232 do {
233 nr = read(fd, fb_buf, buffersize); 233 nr = read(fd, fb_buf, buffersize);
234 } while (nr < 0 && errno == EINTR); 234 } while (nr < 0 && errno == EINTR);
235 if (nr <= 0) 235 if (nr <= 0)
236 break; 236 break;
237 for (off = 0; nr; nr -= nw, off += nw, bytes += nw) 237 for (off = 0; nr; nr -= nw, off += nw, bytes += nw)
238 if ((nw = write(outpipe[1], fb_buf + off, 238 if ((nw = write(outpipe[1], fb_buf + off,
239 (size_t) nr)) < 0) { 239 (size_t) nr)) < 0) {
 240 if (errno == EINTR) {
 241 nw = 0;
 242 continue;
 243 }
240 progressmeter(1); 244 progressmeter(1);
241 err(1, "writing %u bytes to output pipe", 245 err(1, "writing %u bytes to output pipe",
242 (unsigned) nr); 246 (unsigned) nr);
243 } 247 }
244 } 248 }
245 close(outpipe[1]); 249 close(outpipe[1]);
246 250
247 gzipstat = 0; 251 gzipstat = 0;
248 cmdstat = 0; 252 cmdstat = 0;
249 while (pid || gzippid) { 253 while (pid || gzippid) {
250 deadpid = wait(&ws); 254 deadpid = wait(&ws);
251 /* 255 /*
252 * We need to exit with an error if the command (or gzip) 256 * We need to exit with an error if the command (or gzip)