[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#872956: [debian-policy] warn about danger of pipe in shell snippet of makefile



Hi,

Bastien ROUCARIÈS wrote:

> set -e is not suffisant to detect error in pipe context
>
> cat nonexistant | sed s/some//g will hapilly return 0 and do not fail
>
> exec 3>&1; s=$(exec 4>&1 >&3; { cat nonexistant ; echo $? >&4; } | sed s/some//g ) && exit $s
>
> this could be simplified by using make function
> PIPESAFE=exec 3>&1; s=$$(exec 4>&1 >&3; { $(1) ; echo $$? >&4; } | $(2)) && exit $$s
>
> Could deserve a footnote on 4.6. Error trapping in makefiles

I don't think this belongs in policy.  Maybe devref?

By the way, if you're using bash
(https://www.gnu.org/software/make/manual/html_node/Choosing-the-Shell.html),
you can use "set -o pipefail" to handle this kind of case.

Thanks,
Jonathan


Reply to: