>From 5f316c5500c6c62bae9c5a83de711eacd2615611 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup 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