[less] - (lesspipe) better handling of exit status fixing regression of #186931 - turns over the lesspipe

Jozef Mlich jmlich at fedoraproject.org
Thu Jun 19 12:09:22 UTC 2014


commit 632b88cf2108a225241ee06a96a89e8f743e43be
Author: Jozef Mlich <jmlich at redhat.com>
Date:   Thu Jun 19 14:09:08 2014 +0200

    - (lesspipe) better handling of exit status
      fixing regression of #186931 - turns over the lesspipe exit behavior

 less-458-return-non-zero.patch |   12 ++++++++
 less.spec                      |    8 +++++-
 lesspipe.sh                    |   57 +++++++++++++++++++++++-----------------
 3 files changed, 52 insertions(+), 25 deletions(-)
---
diff --git a/less-458-return-non-zero.patch b/less-458-return-non-zero.patch
new file mode 100644
index 0000000..293458b
--- /dev/null
+++ b/less-458-return-non-zero.patch
@@ -0,0 +1,12 @@
+diff -up ./filename.c.return-non-zero ./filename.c
+--- ./filename.c.return-non-zero	2013-04-04 18:55:05.000000000 +0200
++++ ./filename.c	2014-06-19 13:10:50.692171380 +0200
+@@ -915,7 +915,7 @@ open_altfile(filename, pf, pfd)
+ 			 * If only one pipe char, just assume no alt file.
+ 			 */
+ 			int status = pclose(fd);
+-			if (returnfd > 1 && status == 0) {
++			if (returnfd > 1 && status != 0) {
+ 				*pfd = NULL;
+ 				*pf = -1;
+ 				return (save(FAKE_EMPTYFILE));
diff --git a/less.spec b/less.spec
index a02571c..838954e 100644
--- a/less.spec
+++ b/less.spec
@@ -1,7 +1,7 @@
 Summary: A text file browser similar to more, but better
 Name: less
 Version: 458
-Release: 9%{?dist}
+Release: 10%{?dist}
 License: GPLv3+
 Group: Applications/Text
 Source: http://www.greenwoodsoftware.com/less/%{name}-%{version}.tar.gz
@@ -19,6 +19,7 @@ Patch9: less-458-less-filters-man.patch
 Patch10: less-458-lesskey-usage.patch
 Patch11: less-458-old-bot-in-help.patch
 Patch12: less-458-outdated-unicode-data.patch
+Patch13: less-458-return-non-zero.patch
 URL: http://www.greenwoodsoftware.com/less/
 Requires: groff-base
 BuildRequires: ncurses-devel
@@ -47,6 +48,7 @@ files, and you'll use it frequently.
 %patch10 -p1 -b .lesskey-usage
 %patch11 -p1 -b .old-bot
 %patch12 -p1 -b .outdated-unicode-data
+%patch13 -p1 -b .return-non-zero
 autoreconf
 
 chmod -R a+w *
@@ -76,6 +78,10 @@ ls -la $RPM_BUILD_ROOT/etc/profile.d
 rm -rf $RPM_BUILD_ROOT
 
 %changelog
+* Thu Jun 19 2014 Jozef Mlich <jmlich at redhat.com> - 458-10
+- (lesspipe) better handling of exit status
+  fixing regression of #186931 - turns over the lesspipe exit behavior
+
 * Sat Jun 07 2014 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 458-9
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild
 
diff --git a/lesspipe.sh b/lesspipe.sh
index 1a0b0f3..365664d 100755
--- a/lesspipe.sh
+++ b/lesspipe.sh
@@ -11,13 +11,25 @@
 # after the first one in the LESSOPEN environment variable:
 # export LESSOPEN="||/usr/bin/lesspipe.sh %s"
 
+
+# This function turns over return values. 
+# 0 becomes 1 and anything else becomes 0
+# This behavior is forced because backward compatiblity 
+# Bug #186931 - less breaks with tcsh's printexitvalue=1
+function handle_exit_status() {
+  if [ $1 -eq 0 ]; then
+    exit 1
+  fi
+  exit 0
+}
+
 if [ ! -e "$1" ] ; then
-	exit 1
+	handle_exit_status 1 $1 # passing exit status and name of not existing file
 fi
 
 if [ -d "$1" ] ; then
 	ls -alF -- "$1"
-	exit $?
+	handle_exit_status $?
 fi
 
 exec 2>/dev/null
@@ -26,7 +38,7 @@ exec 2>/dev/null
 if [ -x ~/.lessfilter ]; then
 	~/.lessfilter "$1"
 	if [ $? -eq 0 ]; then
-		exit 0
+		handle_exit_status 0
 	fi
 fi
 
@@ -39,35 +51,35 @@ case "$1" in
 	esac
 	if [ -n "$DECOMPRESSOR" ] && $DECOMPRESSOR -- "$1" | file - | grep -q troff; then
 		$DECOMPRESSOR -- "$1" | groff -Tascii -mandoc -
-		exit $?
+		handle_exit_status $?
 	fi ;;&
 *.[1-9n]|*.[1-9]x|*.man)
 	if file "$1" | grep -q troff; then
 		groff -Tascii -mandoc "$1" | cat -s
-		exit $?
+		handle_exit_status $?
 	fi ;;&
-*.tar) tar tvvf "$1" ;;
-*.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1" ;;
-*.tar.xz) tar Jtvvf "$1" ;;
-*.xz|*.lzma) xz -dc -- "$1" ;;
-*.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf - ;;
-*.[zZ]|*.gz) gzip -dc -- "$1" ;;
-*.bz2) bzip2 -dc -- "$1" ;;
-*.zip|*.jar|*.nbm) zipinfo -- "$1" ;;
-*.rpm) rpm -qpivl --changelog -- "$1" ;;
-*.cpi|*.cpio) cpio -itv < "$1" ;;
-*.gpg) gpg -d "$1" ;;
+*.tar) tar tvvf "$1"; handle_exit_status $? ;;
+*.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1"; handle_exit_status $? ;;
+*.tar.xz) tar Jtvvf "$1"; handle_exit_status $? ;;
+*.xz|*.lzma) xz -dc -- "$1"; handle_exit_status $? ;;
+*.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf -; handle_exit_status $? ;;
+*.[zZ]|*.gz) gzip -dc -- "$1"; handle_exit_status $? ;;
+*.bz2) bzip2 -dc -- "$1"; handle_exit_status $? ;;
+*.zip|*.jar|*.nbm) zipinfo -- "$1"; handle_exit_status $? ;;
+*.rpm) rpm -qpivl --changelog -- "$1"; handle_exit_status $? ;;
+*.cpi|*.cpio) cpio -itv < "$1"; handle_exit_status $? ;;
+*.gpg) gpg -d "$1"; handle_exit_status $? ;;
 *.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif)
 	if [ -x /usr/bin/identify ]; then
 		identify "$1"
-		exit $?
+		handle_exit_status $?
 	elif [ -x /usr/bin/gm ]; then
 		gm identify "$1"
-		exit $?
+		handle_exit_status $?
 	else
 		echo "No identify available"
 		echo "Install ImageMagick or GraphicsMagick to browse images"
-		exit 1
+		handle_exit_status 1
 	fi ;;
 *)
 	if [ -x /usr/bin/file ] && [ -x /usr/bin/iconv ] && [ -x /usr/bin/cut ]; then
@@ -79,12 +91,9 @@ case "$1" in
 			env=`echo $LANG | cut -d. -f2`
 			if [ -n "$env" -a "$conv" != "$env" ]; then
 				iconv -f $conv -t $env "$1"
-				exit $?
+				handle_exit_status $?
 			fi
 		fi
 	fi
-	cat "$1"
-	exit $?
+	handle_exit_status 1
 esac
-
-


More information about the scm-commits mailing list