From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2201) id DA0EF395B403; Wed, 25 Nov 2020 13:35:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA0EF395B403 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jon TURNEY To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: Have cygmagic not create output if an error occurs X-Act-Checkin: newlib-cygwin X-Git-Author: Jon Turney X-Git-Refname: refs/heads/master X-Git-Oldrev: 47e698cc04109a188d8bba6be8f7fe2e307410a4 X-Git-Newrev: 7fa8405d3fc166e48f8b401cbd83ce65e694b5a7 Message-Id: <20201125133547.DA0EF395B403@sourceware.org> Date: Wed, 25 Nov 2020 13:35:47 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2020 13:35:48 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7fa8405d3fc166e48f8b401cbd83ce65e694b5a7 commit 7fa8405d3fc166e48f8b401cbd83ce65e694b5a7 Author: Jon Turney Date: Thu Nov 12 17:58:58 2020 +0000 Cygwin: Have cygmagic not create output if an error occurs Improve the 'cygmagic' script, so it doesn't create the output file if an error occurs, even in one of the backtick-enclosed pipelines it runs. Diff: --- winsup/cygwin/cygmagic | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/cygmagic b/winsup/cygwin/cygmagic index c80ca9f96..eee4a3b73 100755 --- a/winsup/cygwin/cygmagic +++ b/winsup/cygwin/cygmagic @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # cygmagic - Generate "magic numbers" from a structure. # # This file is part of Cygwin. @@ -7,14 +7,22 @@ # Cygwin license. Please consult the file "CYGWIN_LICENSE" for # details. +set -e +shopt -s -o pipefail +shopt -s inherit_errexit + file_magic=$1; shift gcc=$1; shift file=$1; shift + +tmpfile=/tmp/$$.magic trap "rm -f /tmp/$$.magic" 0 1 2 15 -cat < $file_magic + +cat < $tmpfile /* autogenerated - do not edit */ #include "$file" EOF + sumit() { cksum $* } @@ -28,5 +36,8 @@ while [ -n "$1" ]; do [ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING *** *** $file: magic number for $define changed old $curr != new $sum *** WARNING WARNING WARNING WARNING WARNING ***" 1>&2 -done >> $file_magic +done >> $tmpfile + +mv $tmpfile $file_magic + exit 0