public inbox for bzip2-devel@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix bzgrep so it doesn't always return a 0 exit code with multiple archives
@ 2019-01-01  0:00 Mark Wielaard
  0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2019-01-01  0:00 UTC (permalink / raw)
  To: bzip2-devel
  Cc: Martin Pluskal, Bjørn Lie, Kristýna Streitová,
	Mark Wielaard

bzip2 lost its domain and got a new home at https://sourceware.org/bzip2/
It also didn't see a release for a very long time. Causing various patches
used by distros to not have been integrated upstream. We are trying to
collect them all and do a new release.

The following patch comes from openSUSE.
Please let us know if we missed some others.

Thanks,

Mark

The bzgrep wrapper always returns 0 as exit code when working on
multiple archives, even when the pattern is not found.

Fix from openSUSE by Kristýna Streitová <kstreitova@suse.com>
https://bugzilla.suse.com/970260
---
 bzgrep | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 bzgrep

diff --git a/bzgrep b/bzgrep
old mode 100644
new mode 100755
index 5080afd..0314ca6
--- a/bzgrep
+++ b/bzgrep
@@ -65,8 +65,20 @@ for i do
   else
     j=$(echo "$i" | sed 's/\\/&&/g;s/|/\\&/g;s/&/\\&/g')
     j=`printf "%s" "$j" | tr '\n' ' '`
-    bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|"
-    r=$?
+    # A trick adapted from
+    # https://groups.google.com/forum/#!original/comp.unix.shell/x1345iu10eg/Nn1n-1r1uU0J
+    # that has the same effect as the following bash code:
+    # bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|"
+    # r=${PIPESTATUS[1]}
+    exec 3>&1
+    eval `
+      exec 4>&1 >&3 3>&-
+      {
+        bzip2 -cdfq "$i" 4>&-
+      } | {
+        $grep $opt "$pat" 4>&-; echo "r=$?;" >&4
+      } | sed "s|^|${j}:|"
+    `
   fi
   test "$r" -ne 0 && res="$r"
 done
-- 
2.20.1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-11 23:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01  0:00 [PATCH] Fix bzgrep so it doesn't always return a 0 exit code with multiple archives Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).