From 08d269fc89eb5962c29772b2fe41ae15a58b11c0 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sat, 17 Apr 2010 01:28:16 -0400 Subject: [PATCH] Make makegen/m4.sh report m4 failure by returning 1. Previously, the return code of m4 was totally ignored, because it was invoked only in a pipeline not at the end. Because of brain damage in shell script, we have to use a temporary file to let the subshell in which we run m4 report the failure to the script so that the script can know to return 1. --- src/microcode/makegen/m4.sh | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/microcode/makegen/m4.sh b/src/microcode/makegen/m4.sh index 2411fc79f..bf01c4490 100755 --- a/src/microcode/makegen/m4.sh +++ b/src/microcode/makegen/m4.sh @@ -24,13 +24,29 @@ # Processing to simulate m4 accepting definition arguments. +set -e + +TMP_FILE="m4.tmp" + +clean () +{ + rm -f "${TMP_FILE}" +} + +run_m4 () +{ + m4 && clean +} + +trap clean EXIT INT QUIT TERM +rm -f "${TMP_FILE}" +touch "${TMP_FILE}" + if [ $# = 0 ] then - sed -e '/^#/D' | m4 | sed -e 's/@/$/g' -e 's/^ $//' + sed -e '/^#/D' | run_m4 | sed -e 's/@/$/g' -e 's/^ $//' else - TMP_FILE="m4.tmp" SEEN_INPUT=0 - rm -f "${TMP_FILE}" while [ $# != 0 ]; do if [ "${1}" = "-P" ]; then echo "define(${2})" >> "${TMP_FILE}" @@ -44,6 +60,13 @@ else if [ ${SEEN_INPUT} -eq 0 ]; then sed -e '/^#/D' >> "${TMP_FILE}" fi - m4 < "${TMP_FILE}" | sed -e 's/@/$/g' -e 's/^ $//' - rm -f "${TMP_FILE}" + run_m4 < "${TMP_FILE}" | sed -e 's/@/$/g' -e 's/^ $//' +fi + +# If m4 was successful, run_m4 has deleted the temporary file. If +# not, report the failure; exiting will have the effect of running +# `clean', which will delete the temporary file. + +if [ -f "${TMP_FILE}" ]; then + exit 1 fi -- 2.25.1