]> Dogcows Code - chaz/tar/commitdiff
Fix undesired error exit on receiving SIGPIPE.
authorSergey Poznyakoff <gray@gnu.org.ua>
Sat, 20 Mar 2010 11:14:31 +0000 (13:14 +0200)
committerSergey Poznyakoff <gray@gnu.org.ua>
Sat, 20 Mar 2010 11:20:30 +0000 (13:20 +0200)
* src/tar.c: Do not ignore SIGPIPE.
* tests/sigpipe.at: New testcase.
* tests/Makefile.am, tests/testsuite.at: Add sigpipe.at
* tests/remfiles01.at: Fix error code expectation.
* NEWS: Update.

NEWS
src/tar.c
tests/Makefile.am
tests/remfiles01.at
tests/sigpipe.at [new file with mode: 0644]
tests/testsuite.at

diff --git a/NEWS b/NEWS
index a9be03c2a5efbfc14bab115dff8c8f4f979e17eb..8b55ece0a025cef8934c3482e52664fc7b3354f2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,18 @@
-GNU tar NEWS - User visible changes. 2010-03-17
+GNU tar NEWS - User visible changes. 2010-03-20
 Please send GNU tar bug reports to <bug-tar@gnu.org>
 
 \f
 
 * Bugfixes.
 
+** Spurious error diagnostics on broken pipe.
+
+When receiving SIGPIPE, tar would exit with error status and
+"write error" diagnostics. In particular, this occurred if
+invoked as in the example below:
+
+   tar tf archive.tar | head -n 1
+
 ** --remove-files
 
 Tar --remove-files failed to remove a directory which contained
index e3fdf7bcfa7f837d4ecb7cd87d20288c7f688a22..b127963fb58298074b634f6efec30b17a44570e9 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -2570,8 +2570,6 @@ main (int argc, char **argv)
 
   obstack_init (&argv_stk);
 
-  /* Ensure default behavior for some signals */
-  signal (SIGPIPE, SIG_IGN);
   /* System V fork+wait does not work if SIGCHLD is ignored.  */
   signal (SIGCHLD, SIG_DFL);
 
index 8f1624420b673243feeaa980b4bcbf7fda2fca5a..31811b0c7303e6c485c144e94f5a0cf80c459d65 100644 (file)
@@ -127,6 +127,7 @@ TESTSUITE_AT = \
  shortfile.at\
  shortupd.at\
  shortrec.at\
+ sigpipe.at\
  sparse01.at\
  sparse02.at\
  sparse03.at\
index 73752b4a450d72bdc17abd5f2af43be6a5cbb663..86b5c032e8c996f7e279f187619380a1a18923de 100644 (file)
@@ -52,7 +52,9 @@ EC=$?
 sed -n '/(child)/p' err >&2
 rm err
 find . | sort
-exit $EC
+# Gzip exit code is propagated to the shell. Usually it is
+# 141.  We convert all non-zero exits to 2 to make it predictable.
+test $EC && exit 2
 ],
 [2],
 [.
diff --git a/tests/sigpipe.at b/tests/sigpipe.at
new file mode 100644 (file)
index 0000000..9edca77
--- /dev/null
@@ -0,0 +1,39 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright (C) 2010 Free Software Foundation, Inc.
+
+# This program 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, or (at your option)
+# any later version.
+
+# This program 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([sigpipe handling])
+AT_KEYWORDS([sigpipe])
+
+# Description: Tar 1.23 ignored sigpipe which lead to spurious "write
+# error" diagnostics when piping output to another programs.
+# Reported-by: "Dmitry V. Levin" <ldv@altlinux.org>
+# References: http://lists.gnu.org/archive/html/bug-tar/2010-03/msg00039.html
+#             <20100319184141.GC30047@wo.int.altlinux.org>
+
+AT_CHECK([
+genfile --length 2048 --file first
+genfile --length 2048 --file second
+genfile --length 2049 --file third
+
+tar cf archive first second third
+
+tar tf archive | :
+],
+[0])
+
+AT_CLEANUP
index 3e75ed8c8db68b2599191a35aaabb5092262d9c7..9205d5213f17db03e180a1303748ffd92b029af0 100644 (file)
@@ -231,6 +231,8 @@ m4_include([remfiles01.at])
 m4_include([remfiles02.at])
 m4_include([remfiles03.at])
 
+m4_include([sigpipe.at])
+
 m4_include([star/gtarfail.at])
 m4_include([star/gtarfail2.at])
 
This page took 0.028694 seconds and 4 git commands to generate.