On Mon, 2013-02-25 at 11:39 -0800, Paul Eggert wrote:
> I suggest something simpler: namely, just declare that the
> -Z (compress) program must conform to the compress API,
> so that its exit status 2 really means OK.  That way,
> we can change only src/system.c and NEWS.  The compress API
> is obsolete and isn't likely to change so this sounds safe.

Thanks for comments!  Attaching approach with just src/system.c
and NEWS edited.

Pavel

>From eab80fb7c5a5500a9d4c20321b4f00e019cb3735 Mon Sep 17 00:00:00 2001
From: Pavel Raiskup <[email protected]>
Date: Mon, 25 Feb 2013 10:18:15 +0100
Subject: [PATCH] tar: The Lempel-Ziv coding handler bugfix

Do not exit with fatal error 2 after compressing tarball by the
'compress' utility (-Z option) when the child process running the
compressor exited with "just-a-warning" exit value 2 (compressed
output is larger than original data).

* src/system.c (sys_wait_for_child): Warn only when child process
exited with 2 and the compressing command was called 'compress'.
* NEWS: Document.
---
 NEWS         | 11 +++++++++++
 src/system.c |  7 +++++++
 2 files changed, 18 insertions(+)

diff --git a/NEWS b/NEWS
index 3108798..17df594 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,17 @@ version 1.26.90 (Git)
 
 * Bug fixes
 
+** The Lempel-Ziv coding compression bugfix (compress)
+
+Do not exit with fatal error 2 after the tarball compressing when
+the tar's child 'compress' process (-Z option) exited with
+"just-a-warning" exit value 2.  It just means that output of the
+'compress' utility became bigger than it's original data
+(insufficient compress ratio).  Tar just warns now under these
+circumstances instead of failing hard.  Any compressor used by the
+'-Z' option must conform to compress API now - thus the exit value
+'2' must signify successful exit status.
+
 ** Sparse files with large data
 
 When creating a PAX-format archive, tar no longer arbitrarily restricts
diff --git a/src/system.c b/src/system.c
index e1fd263..10f76a3 100644
--- a/src/system.c
+++ b/src/system.c
@@ -189,6 +189,13 @@ sys_wait_for_child (pid_t child_pid, bool eof)
 	  if (!(!eof && sig == SIGPIPE))
 	    FATAL_ERROR ((0, 0, _("Child died with signal %d"), sig));
 	}
+      /* Any compressor used by the '-Z' option must conform to the 'compress'
+         API - value 2 is "OK" exit status (not a fatal error) */
+      else if (WEXITSTATUS (wait_status) == 2
+	       && !strcmp (use_compress_program_option, COMPRESS_PROGRAM))
+        WARN ((0, 0, _("%lu: Child says that compressed output is larger "
+		       "than original data."),
+	       (unsigned long) child_pid));
       else if (WEXITSTATUS (wait_status) != 0)
 	FATAL_ERROR ((0, 0, _("Child returned status %d"),
 		      WEXITSTATUS (wait_status)));
-- 
1.8.1.2

Reply via email to