catching errors in pipelines (was: dbootstrap/po/Makefile gawk bug)
[Cc: very widely extended]
On 31 Jul, Junichi Uekawa wrote:
>
> It's not that pipelines in Makefile are evil.
>
> pipeline in shell is.
Yes, you are right. Either in Makefiles or elsewhere, checking failures
in shell pipelines is always tricky.
But I found interesting solutions in USENET archives. Among them there
is this good thread, worth a read :
<http://groups.google.com/groups?threadm=522%40cpsolv.CPS.COM>
Warning: Larry Wall will try to sell you Perl somewhere in this thread.
I find that the solution given in the last message of the thread above,
using signals and traps, is the most elegant one.
If we translate it to dbootstrap/po/Makefile, this gives the attached
patch, that works perfectly. Please consider it.
Trying to be exaustive, I found the following choices to implement
exceptions in pipelines.
1. signals (trap + kill)
3. file descriptors > 1
2. using temp files, like I proposed previously
<http://lists.debian.org/debian-boot/2002/debian-boot-200207/msg00017.html>
4. using bash2 $PIPESTATUS array. Non-"portable".
PS: Google rocks.
PPS: we are not subscribed to the list (too many CVS commits). Please
keep us in Cc: if needed.
Index: Makefile
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/po/Makefile,v
retrieving revision 1.52
diff -u -r1.52 Makefile
--- Makefile 2002/07/02 16:38:07 1.52
+++ Makefile 2002/07/31 11:05:51
@@ -60,7 +60,8 @@
./finduntranslated.pl $$lang.po
C.po: $(PACKAGE).pot genc.awk
- set -e; gawk -f genc.awk < $(PACKAGE).pot | \
+ trap 'exit 9' 15; \
+ { gawk -f genc.awk < $(PACKAGE).pot || kill $$$$; } | \
sed \
-e "s/PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE/PO-Revision-Date: `date -R`/" \
-e "s/Last-Translator: FULL NAME <EMAIL@ADDRESS>/Last-Translator: Automagic/" \
Reply to: