diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2020-11-12 17:58:58 +0000 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2020-11-25 13:34:18 +0000 |
commit | 7fa8405d3fc166e48f8b401cbd83ce65e694b5a7 (patch) | |
tree | f769e1a3ab8821412517dc8b6870bae4d4d613fb | |
parent | 47e698cc04109a188d8bba6be8f7fe2e307410a4 (diff) | |
download | cygnal-7fa8405d3fc166e48f8b401cbd83ce65e694b5a7.tar.gz cygnal-7fa8405d3fc166e48f8b401cbd83ce65e694b5a7.tar.bz2 cygnal-7fa8405d3fc166e48f8b401cbd83ce65e694b5a7.zip |
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.
-rwxr-xr-x | winsup/cygwin/cygmagic | 17 |
1 files 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 |