Mark Nudelman wrote:
Since less-451, if LESSOPEN starts with two pipe chars, less does
examine the exit status of the preprocessor.

Thanks, I didn't know that, and I have installed the attached patch to the gzip master on savannah to take advantage of it. Unfortunately the patch doesn't suffice, because 'less' examines the preprocessor's exit status only when the preprocessor generates no output. In the case we're talking about, the preprocessor generates some output, but then runs out of memory and exits with nonzero status.

You can reproduce the 'less' problem by creating a large text file 't', compressing it with 'gzip t', running the following shell command in one window:

LESSOPEN='||-gzip -cdfq -- %s' less t.gz

When you see the first screenful, go to another window and kill the gzip process that's waiting for 'less' to read more input. 'less' won't notice or report the gzip failure.
From c0beeb5bc3c7120fea67eb9122f467e646abb6ed Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Thu, 6 Mar 2014 17:31:25 -0800
Subject: [PATCH] zless: improve gzip failure checking, and port to new -V
 format

Problem reported by Jaroslaw Weglinski, and LESSOPEN change
suggested by Mark Nudelman, in: http://bugs.gnu.org/16951
This doesn't fix bug 16951 entirely, as 'less' needs to be changed
too, but it's a start.
* zless.in (check_exit_status): New var.
(LESSOPEN): Use it.
(use_input_pipe_on_stdin): Adjust to output format on Fedora 20,
where 'less -V' outputs "less 458 (POSIX regular expressions)"
on the first line.
---
 zless.in | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/zless.in b/zless.in
index 92209f2..67760b3 100644
--- a/zless.in
+++ b/zless.in
@@ -55,13 +55,23 @@ fi
 
 less_version=`less -V` || exit
 case $less_version in
-'less 429
-'* | 'less '4[3-9][0-9]* | 'less '[5-9][0-9][0-9]* | 'less 
'[1-9][0-9][0-9][0-9]*)
+less' '45[1-9]* | \
+less' '4[6-9][0-9]* | \
+less' '[5-9][0-9][0-9]* | \
+less' '[1-9][0-9][0-9][0-9]*)
+   check_exit_status='|';;
+*) check_exit_status='';;
+esac
+case $less_version in
+less' '429* | \
+less' '4[3-9][0-9]* | \
+less' '[5-9][0-9][0-9]* | \
+less' '[1-9][0-9][0-9][0-9]*)
    use_input_pipe_on_stdin='-';;
 *) use_input_pipe_on_stdin='';;
 esac
 
-LESSOPEN="|${use_input_pipe_on_stdin}gzip -cdfq -- %s"
+LESSOPEN="|$check_exit_status${use_input_pipe_on_stdin}gzip -cdfq -- %s"
 export LESSOPEN
 
 exec less "$@"
-- 
1.8.5.3

Reply via email to