- Don't require correct exit status from LESSOPEN scripts

This commit is contained in:
Vojtech Vitek (V-Teq) 2011-02-09 16:59:28 +01:00
parent 194a24bd08
commit 4f44bc69b5
4 changed files with 66 additions and 10 deletions

View File

@ -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.

View File

@ -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

View File

@ -72,12 +72,16 @@ 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 Feb 07 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 436-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild
* Mon Jan 03 2011 Vojtech Vitek (V-Teq) <vvitek@redhat.com> - 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) <vvitek@redhat.com> - 436-8
- The new "--old-bot" option is not documented in the man page

View File

@ -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