public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jon TURNEY <jturney@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: Have cygmagic not create output if an error occurs
Date: Wed, 25 Nov 2020 13:35:47 +0000 (GMT)	[thread overview]
Message-ID: <20201125133547.DA0EF395B403@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7fa8405d3fc166e48f8b401cbd83ce65e694b5a7

commit 7fa8405d3fc166e48f8b401cbd83ce65e694b5a7
Author: Jon Turney <jon.turney@dronecode.org.uk>
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 <<EOF > $file_magic
+
+cat <<EOF > $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


                 reply	other threads:[~2020-11-25 13:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201125133547.DA0EF395B403@sourceware.org \
    --to=jturney@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).