]> git.gag.com Git - debian/tar/commitdiff
Catch compressor execution errors.
authorSergey Poznyakoff <gray@gnu.org.ua>
Sat, 5 Dec 2015 14:54:26 +0000 (16:54 +0200)
committerSergey Poznyakoff <gray@gnu.org.ua>
Sat, 5 Dec 2015 14:54:26 +0000 (16:54 +0200)
* src/misc.c (write_fatal_details): Move to buffer.c
* src/buffer.c (write_fatal_details): Close the archive and wait for
the compressor program to terminate in order to catch eventual execution
errors.
* src/system.c (sys_child_open_for_compress): Ignore SIGPIPE so tar will
not silently terminate when unable to write to the compressor.
* tests/comperr.at: New file.
* tests/Makefile.am: Add comperr.at
* tests/testsuite.at: Include comperr.at

src/buffer.c
src/misc.c
src/system.c
tests/Makefile.am
tests/comperr.at [new file with mode: 0644]
tests/testsuite.at

index 17c4753f9b16a3ecb57d746048c10e010817a90d..e32c628de8821500229023f921ff1f0a186ce32c 100644 (file)
@@ -1115,6 +1115,16 @@ close_archive (void)
   bufmap_free (NULL);
 }
 
+void
+write_fatal_details (char const *name, ssize_t status, size_t size)
+{
+  write_error_details (name, status, size);
+  if (rmtclose (archive) != 0)
+    close_error (*archive_name_cursor);
+  sys_wait_for_child (child_pid, false);
+  fatal_exit ();
+}
+
 /* Called to initialize the global volume number.  */
 void
 init_volume_number (void)
index 4cbfa42dd022c648414427c43d42cc140b32d5c0..d3bb0e42fe5bd11470d9ed832c51bd2380d9098d 100644 (file)
@@ -1113,13 +1113,6 @@ file_removed_diag (const char *name, bool top_level,
     diagfn (name);
 }
 
-void
-write_fatal_details (char const *name, ssize_t status, size_t size)
-{
-  write_error_details (name, status, size);
-  fatal_exit ();
-}
-
 /* Fork, aborting if unsuccessful.  */
 pid_t
 xfork (void)
index 94142336ef6d021868836cf94a97720ee9d20429..dc0b2b0b7811e3a443b5f442cede1d15eee47c20 100644 (file)
@@ -330,6 +330,7 @@ sys_child_open_for_compress (void)
   pid_t grandchild_pid;
   pid_t child_pid;
 
+  signal (SIGPIPE, SIG_IGN);
   xpipe (parent_pipe);
   child_pid = xfork ();
 
index d9a52b3e7714571ab1b5f65c55dd3b4cc6c780be..f1d124108929365b21bace24ef635d6d44507633 100644 (file)
@@ -62,6 +62,7 @@ TESTSUITE_AT = \
  backup01.at\
  chtype.at\
  comprec.at\
+ comperr.at\
  delete01.at\
  delete02.at\
  delete03.at\
diff --git a/tests/comperr.at b/tests/comperr.at
new file mode 100644 (file)
index 0000000..4d3da19
--- /dev/null
@@ -0,0 +1,39 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+# Test suite for GNU tar.
+# Copyright 2015 Free Software Foundation, Inc.
+#
+# GNU tar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# GNU tar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([compressor program failure])
+AT_KEYWORDS([compress comperr])
+
+# Description: If the --use-compress-program fails, then it is unsafe
+# to assume that the created archive is OK.  Tar should fail with a
+# prominent error message.
+# Reported by: Ole Tange <tange@gnu.org>
+# References: <CA+4vN7wLZ-+LK1t7WMkM_b9f3mV9JTnSuPamPn2ciX5PTN=9Xw@mail.gmail.com>,
+#        http://lists.gnu.org/archive/html/bug-tar/2015-03/msg00002.html
+
+AT_TAR_CHECK([
+tar --use-compress-program false -cf a.tar . 2>err
+rc=$?
+sed -n '$p' err
+exit $rc
+],
+[2],
+[tar: Error is not recoverable: exiting now
+])
+
+AT_CLEANUP
+
index 085011c62f867f0f98917ace87b0909ba1d2855e..a08dc7717b280ed26710282812c332a5f9424f1f 100644 (file)
@@ -383,6 +383,7 @@ m4_include([shortupd.at])
 m4_include([truncate.at])
 m4_include([grow.at])
 m4_include([sigpipe.at])
+m4_include([comperr.at])
 
 AT_BANNER([Removing files after archiving])
 m4_include([remfiles01.at])