delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/07/29/19:33:59

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Wed, 29 Jul 2009 19:31:38 -0400
From: Christopher Faylor <cgf-use-the-mailinglist-please AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: bash pipeline exit code - possible race condition?
Message-ID: <20090729233138.GD13645@ednor.casa.cgf.cx>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <db95995b0907282216g6f90bcb0t5ee80873a383eb29 AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <db95995b0907282216g6f90bcb0t5ee80873a383eb29@mail.gmail.com>
User-Agent: Mutt/1.5.20 (2009-06-14)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019