This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bash pipeline exit code - possible race condition?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]