From 27567f085b4bf66e729512b36197e3288b5a19d2 Mon Sep 17 00:00:00 2001 From: "Vojtech Vitek (V-Teq)" Date: Wed, 9 Feb 2011 16:59:28 +0100 Subject: [PATCH] - Don't require correct exit status from LESSOPEN scripts --- less-436-empty-lessopen-pipe.patch | 58 +++++++++++++++++++++++++++--- less.csh | 2 +- less.spec | 6 +++- lesspipe.sh | 10 ++++-- 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/less-436-empty-lessopen-pipe.patch b/less-436-empty-lessopen-pipe.patch index 41311d4..69f84ca 100644 --- a/less-436-empty-lessopen-pipe.patch +++ b/less-436-empty-lessopen-pipe.patch @@ -1,6 +1,24 @@ ---- less-436/filename.c 2009-07-06 22:52:23.000000000 +0200 -+++ less-436_vvitek/filename.c 2010-12-08 16:01:41.269695932 +0100 -@@ -879,17 +879,32 @@ open_altfile(filename, pf, pfd) +diff -rup less-436-orig/filename.c less-436/filename.c +--- less-436-orig/filename.c 2009-07-06 22:52:23.000000000 +0200 ++++ less-436/filename.c 2011-02-09 16:36:59.508940154 +0100 +@@ -843,6 +843,16 @@ open_altfile(filename, pf, pfd) + #else + lessopen++; + returnfd = 1; ++ ++ if (*lessopen == '|') { ++ /* ++ * If there is another vertical bar |, after ++ * the first one, it indicates a "pipe preprocessor" ++ * with correct exit status. ++ */ ++ lessopen++; ++ returnfd = 2; ++ } + #endif + } + if (*lessopen == '-') { +@@ -879,17 +888,32 @@ open_altfile(filename, pf, pfd) */ f = fileno(fd); SET_BINARY(f); @@ -10,11 +28,11 @@ { /* - * Pipe is empty. This means there is no alt file. -+ * Error or pipe is empty. Close it and ++ * Error or pipe is empty. Close it and eventually + * check exit status of the pipe process. */ - pclose(fd); -+ if (pclose(fd) == 0) { ++ if (pclose(fd) == 0 && returnfd == 2) { + /* + * Exit status was zero, so the EOF was correct + * empty output. Let the program open /dev/null @@ -37,3 +55,33 @@ return (save("-")); } #endif +diff -rup less-436-orig/less.nro less-436/less.nro +--- less-436-orig/less.nro 2011-02-09 16:00:12.520936431 +0100 ++++ less-436/less.nro 2011-02-09 16:30:33.161235986 +0100 +@@ -1147,11 +1147,26 @@ lesspipe.sh: + .br + ;; + .br ++ *) exit 1 ++.br ++ ;; ++.br + esac + .br ++ exit $? ++.br + .PP + To use this script, put it where it can be executed and set + LESSOPEN="|lesspipe.sh %s". ++.PP ++The script should return zero if the output was valid and non-zero ++otherwise, so less could detect even a valid empty output ++(for example while uncompressing gzipped empty file). ++For backward-compatibility, this is not required by default. To turn ++this functionality there should be another vertical bar (|) straight ++after the first one in the LESSOPEN environment variable, eg. ++LESSOPEN="||lesspipe.sh %s". ++.PP + When an input pipe is used, a LESSCLOSE postprocessor can be used, + but it is usually not necessary since there is no replacement file + to clean up. diff --git a/less.csh b/less.csh index 709dc2d..ba2b82b 100755 --- a/less.csh +++ b/less.csh @@ -1,4 +1,4 @@ # less initialization script (csh) if ( -x /usr/bin/lesspipe.sh ) then - setenv LESSOPEN "|/usr/bin/lesspipe.sh %s" + setenv LESSOPEN "||/usr/bin/lesspipe.sh %s" endif diff --git a/less.spec b/less.spec index 5304bb5..16f9952 100644 --- a/less.spec +++ b/less.spec @@ -72,9 +72,13 @@ ls -la $RPM_BUILD_ROOT/etc/profile.d rm -rf $RPM_BUILD_ROOT %changelog +- Don't require correct exit status from LESSOPEN scripts until + it gets accepted by upstream (preserve backward compatibility) + Resolves: #666084, #676057 + * Mon Jan 03 2011 Vojtech Vitek (V-Teq) - 436-9 - Fix regression in lesspipe.sh script (*.gz files etc.) - Resolves #615303 (comment #9) + Resolves: #615303 (comment #9) * Wed Dec 22 2010 Vojtech Vitek (V-Teq) - 436-8 - The new "--old-bot" option is not documented in the man page diff --git a/lesspipe.sh b/lesspipe.sh index 428309a..71b2044 100755 --- a/lesspipe.sh +++ b/lesspipe.sh @@ -3,9 +3,13 @@ # To use this filter with less, define LESSOPEN: # export LESSOPEN="|/usr/bin/lesspipe.sh %s" # -# Script should return zero on success. This is important in case -# of empty output of any decompressor when the output pipe produces -# just EOF (eg. while uncompressing gzipped empty file). +# The script should return zero if the output was valid and non-zero +# otherwise, so less could detect even a valid empty output +# (for example while uncompressing gzipped empty file). +# For backward-compatibility, this is not required by default. To turn +# this functionality there should be another vertical bar (|) straight +# after the first one in the LESSOPEN environment variable: +# export LESSOPEN="||/usr/bin/lesspipe.sh %s" lesspipe() { case "$1" in