On Tuesday, February 26, 2013 08:32:25 AM Pavel Raiskup wrote:
> 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.

Hi, I have looked once again on usual compressors and I see now that not
only 'compress' API exits with 2 exit status in case of warning .. 'gzip',
'xz', 'lzma' and 'lzop' behave similarly.

Attaching probably better fix, any comment is welcome!

Pavel
>From 5f316c5500c6c62bae9c5a83de711eacd2615611 Mon Sep 17 00:00:00 2001
From: Pavel Raiskup <prais...@redhat.com>
Date: Mon, 25 Feb 2013 10:18:15 +0100
Subject: [PATCH] tar: do not fail hardly when compressor just warns
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Usual compressor exit status API is that 0 means successful
compression, 1 is fatal error and 2 is warning.  The two
exceptions used by tar by default are Bzip2 and lzip at the
moment — any non-zero value is fatal error.

* src/system.c (sys_wait_for_child): Warn only when child process
exited with 2 and the compressing command wasn't bzip2 or lzip.
* NEWS: Document.
---
 NEWS         |  9 +++++++++
 src/system.c | 22 +++++++++++++++++++---
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 3108798..aa8c82e 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,15 @@ version 1.26.90 (Git)
 
 * Bug fixes
 
+** tar successes now when compressor warns only
+
+Tar does not fail with fatal exit status 2 if the tar's child
+compressor exited with warning exit status 2.  This is usual default
+for 'xz', 'gzip', 'compress', 'lzop' and 'lzma' compressors.  The
+'bzip2' and 'lzip' compressors are throwing non-zero exit status in
+case of fatal error.  Tar still fails hardly if user specified script
+passed by --use-compress-program returns non-zero 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..4cd12e9 100644
--- a/src/system.c
+++ b/src/system.c
@@ -189,9 +189,25 @@ sys_wait_for_child (pid_t child_pid, bool eof)
 	  if (!(!eof && sig == SIGPIPE))
 	    FATAL_ERROR ((0, 0, _("Child died with signal %d"), sig));
 	}
-      else if (WEXITSTATUS (wait_status) != 0)
-	FATAL_ERROR ((0, 0, _("Child returned status %d"),
-		      WEXITSTATUS (wait_status)));
+      /* Exit value of common compressors usually conforms to following
+         defaults: 0 is successful compression, 1 is fatal error and 2 is
+         warning.
+         Bzip2 and lzip return non-zero value in case of fatal error - use
+         this as default behavior also for user-defined scripts.
+         */
+      else if (WEXITSTATUS (wait_status) == 0)
+        return;
+      else if (WEXITSTATUS (wait_status) == 2
+               && (!strcmp (use_compress_program_option, GZIP_PROGRAM)
+                || !strcmp (use_compress_program_option, XZ_PROGRAM)
+                || !strcmp (use_compress_program_option, LZMA_PROGRAM)
+                || !strcmp (use_compress_program_option, LZOP_PROGRAM)
+                || !strcmp (use_compress_program_option, COMPRESS_PROGRAM)))
+        WARN ((0, 0, _("%lu: Child (compressor '%s') exited with warning"),
+               (unsigned long) child_pid, use_compress_program_option));
+      else
+        FATAL_ERROR ((0, 0, _("Child '%s' returned exit status %d"),
+                      use_compress_program_option, WEXITSTATUS (wait_status)));
     }
 }
 
-- 
1.8.1.4

Reply via email to