This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: bash pipeline exit code - possible race condition?
- From: Christopher Faylor <cgf-use-the-mailinglist-please at cygwin dot com>
- To: cygwin at cygwin dot com
- Date: Wed, 29 Jul 2009 19:31:38 -0400
- Subject: Re: bash pipeline exit code - possible race condition?
- References: <db95995b0907282216g6f90bcb0t5ee80873a383eb29@mail.gmail.com>
- Reply-to: cygwin at cygwin dot com
On Wed, Jul 29, 2009 at 05:16:24PM +1200, David Antliff wrote:
>I've noticed a strange problem with bash pipelines in Cygwin that
>might indicate some sort of race condition. I cannot reproduce the
>problem on a Linux system, but it seems easy to reproduce in Cygwin.
>
>I'm running the following command in a bash script that builds some software:
>
>/usr/bin/make --version | head -1
>
>I then test the exit code ($?) against zero and abort if it's non-zero.
>
>Before this executes I have set:
>set -o pipefail
>
>This is to ensure that if any command in a pipeline fails, the entire
>command will return a failed error code. I.e. if make returns
>non-zero, then $? will be non-zero. Without "pipefail", $? is set to
>the exit code of the last process in the pipeline (head), regardless
>of the error code of preceding programs (make).
>
>I am doing this because I want the script to log the version of Make
>that it is using, as well as verify that the make binary is present.
>Most of the time this works fine, $? is zero, and the script continues
>happily.
>
>However occasionally $? comes back as the value "141". I think that
>this value is coming from make because if I turn pipefail off, the
>error code is always zero and never 141, and there's nothing else in
>the pipeline. QED.
>
>This is very curious (and causes my script to break occasionally) so I
>wrote a little script to test this out:
>
>#!/bin/bash
>set -o pipefail
>err_count=0
>count=0
>while : ; do
> count=$((count + 1))
> /usr/bin/make --version | head -1 > /dev/null
> EC=$?
> if (( EC != 0 )) ; then
> err_count=$((err_count+1))
> echo "$count : $EC ($err_count)"
> fi
>done
This doesn't appear to be a cygwin problem. I get occasional errors
on linux as well.
cgf
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple