From 53e0d06e7be1f92b7d46218c7844a9738dd1e7cf Mon Sep 17 00:00:00 2001 From: sobomax Date: Thu, 7 Feb 2002 10:38:16 +0000 Subject: When unpacking compressed archive check exit status of the child (gzip or bzip) and exit with error code if that status != 0. PR: 30876 Submitted by: Simon Gerraty --- gnu/usr.bin/tar/buffer.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/usr.bin/tar/buffer.c b/gnu/usr.bin/tar/buffer.c index 992b322..11b33d4 100644 --- a/gnu/usr.bin/tar/buffer.c +++ b/gnu/usr.bin/tar/buffer.c @@ -1256,6 +1256,21 @@ close_archive () if (f_verify) verify_volume (); +#ifndef __MSDOS__ + /* + * Closing the child's pipe before reading EOF guarantees that it + * will be unhappy - SIGPIPE, or exit 1. + * Either way it can screw us, so play nice. + */ + if (childpid && ar_reading) + { + char buf[BUFSIZ]; + + while ((c = read(archive, buf, sizeof(buf))) > 0) + ; + } +#endif + if ((c = rmtclose (archive)) < 0) msg_perror ("Warning: can't close %s(%d,%d)", ar_files[cur_ar_file], archive, c); @@ -1294,8 +1309,11 @@ close_archive () /* Do nothing. */ } else if (WEXITSTATUS (status)) - msg ("child returned status %d", - WEXITSTATUS (status)); + { + msg ("child returned status %d", + WEXITSTATUS (status)); + exit (EX_BADARCH); + } } } } -- cgit v1.1