From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sa-prd-fep-040.btinternet.com (mailomta10-sa.btinternet.com [213.120.69.16]) by sourceware.org (Postfix) with ESMTPS id 125EA396E85A for ; Fri, 20 Nov 2020 14:09:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 125EA396E85A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dronecode.org.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=jon.turney@dronecode.org.uk Received: from sa-prd-rgout-003.btmx-prd.synchronoss.net ([10.2.38.6]) by sa-prd-fep-040.btinternet.com with ESMTP id <20201120140919.WKZR29410.sa-prd-fep-040.btinternet.com@sa-prd-rgout-003.btmx-prd.synchronoss.net>; Fri, 20 Nov 2020 14:09:19 +0000 Authentication-Results: btinternet.com; none X-SNCR-Rigid: 5ED9AFBE1B580F4F X-Originating-IP: [86.139.158.14] X-OWM-Source-IP: 86.139.158.14 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedujedrudegtddgheekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeflohhnucfvuhhrnhgvhicuoehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkqeenucggtffrrghtthgvrhhnpeefieduveehgfffffeuueehleefgeevfedvffeljeefheduteelteelvdettefhvdenucfkphepkeeirddufeelrdduheekrddugeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhephhgvlhhopehlohgtrghlhhhoshhtrdhlohgtrghlughomhgrihhnpdhinhgvthepkeeirddufeelrdduheekrddugedpmhgrihhlfhhrohhmpeeojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqpdhrtghpthhtohepoegthihgfihinhdqphgrthgthhgvshestgihghifihhnrdgtohhmqedprhgtphhtthhopeeojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheq X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from localhost.localdomain (86.139.158.14) by sa-prd-rgout-003.btmx-prd.synchronoss.net (5.8.340) (authenticated as jonturney@btinternet.com) id 5ED9AFBE1B580F4F; Fri, 20 Nov 2020 14:09:19 +0000 From: Jon Turney To: cygwin-patches@cygwin.com Cc: Jon Turney Subject: [PATCH 3/3] Have cygmagic not create output if an error occurs Date: Fri, 20 Nov 2020 14:09:01 +0000 Message-Id: <20201120140901.44474-4-jon.turney@dronecode.org.uk> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201120140901.44474-1-jon.turney@dronecode.org.uk> References: <20201120140901.44474-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1200.7 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin-patches@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component patch submission and discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Nov 2020 14:09:21 -0000 Improve cygmagic so it doesn't create the output file if an error occurs, even in one of the backtick-enclosed pipelines it runs. --- 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 -- 2.29.2