svn commit: r223541 - head/usr.bin/tar

Tim Kientzle kientzle at FreeBSD.org
Sat Jun 25 16:27:49 UTC 2011


Author: kientzle
Date: Sat Jun 25 16:27:49 2011
New Revision: 223541
URL: http://svn.freebsd.org/changeset/base/223541

Log:
  If there is a read error reading Y/N confirmation from the keyboard,
  exit immediately with an error.
  
  If there is an error opening or reading a file to put into the archive,
  set the return value for a deferred error exit.
  
  PR:		bin/154407

Modified:
  head/usr.bin/tar/util.c
  head/usr.bin/tar/write.c

Modified: head/usr.bin/tar/util.c
==============================================================================
--- head/usr.bin/tar/util.c	Sat Jun 25 16:13:56 2011	(r223540)
+++ head/usr.bin/tar/util.c	Sat Jun 25 16:27:49 2011	(r223541)
@@ -226,7 +226,11 @@ yes(const char *fmt, ...)
 	fflush(stderr);
 
 	l = read(2, buff, sizeof(buff) - 1);
-	if (l <= 0)
+	if (l < 0) {
+	  fprintf(stderr, "Keyboard read failed\n");
+	  exit(1);
+	}
+	if (l == 0)
 		return (0);
 	buff[l] = 0;
 

Modified: head/usr.bin/tar/write.c
==============================================================================
--- head/usr.bin/tar/write.c	Sat Jun 25 16:13:56 2011	(r223540)
+++ head/usr.bin/tar/write.c	Sat Jun 25 16:27:49 2011	(r223541)
@@ -919,6 +919,7 @@ write_entry_backend(struct bsdtar *bsdta
 		const char *pathname = archive_entry_sourcepath(entry);
 		fd = open(pathname, O_RDONLY | O_BINARY);
 		if (fd == -1) {
+			bsdtar->return_value = 1;
 			if (!bsdtar->verbose)
 				bsdtar_warnc(errno,
 				    "%s: could not open file", pathname);
@@ -1020,6 +1021,12 @@ write_file_data(struct bsdtar *bsdtar, s
 		progress += bytes_written;
 		bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN);
 	}
+	if (bytes_read < 0) {
+		bsdtar_warnc(errno,
+			     "%s: Read error",
+			     archive_entry_pathname(entry));
+		bsdtar->return_value = 1;
+	}
 	return 0;
 }
 


More information about the svn-src-all mailing list