summaryrefslogtreecommitdiffstats
path: root/sys/boot
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2015-10-24 21:59:58 +0000
committerngie <ngie@FreeBSD.org>2015-10-24 21:59:58 +0000
commit286d8e974ce705f7c5df2cbc72a2b5fc54f115ef (patch)
treed96a2ad46a71e02a10d0886e86017eece1f7ba15 /sys/boot
parent326fa7f3504250a84134ebacca461528a7c11c86 (diff)
downloadFreeBSD-src-286d8e974ce705f7c5df2cbc72a2b5fc54f115ef.zip
FreeBSD-src-286d8e974ce705f7c5df2cbc72a2b5fc54f115ef.tar.gz
Make vers.c creation atomic by using a temporary file, then moving
the temporary file to vers.c at the end of the script The previous logic wrote out to vers.c multiple times, so the file could be incorrectly interpreted as being completely written out after one of the echo calls with recursive make, when in reality it was only partially written. Also, in the event the build was interrupted when creating vers.c (small race window), it would have a leftover file that needed to be cleaned up before resuming the build. MFC after: 3 weeks Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'sys/boot')
-rwxr-xr-xsys/boot/common/newvers.sh12
1 files changed, 8 insertions, 4 deletions
diff --git a/sys/boot/common/newvers.sh b/sys/boot/common/newvers.sh
index fd7b0b1..ee2ac99 100755
--- a/sys/boot/common/newvers.sh
+++ b/sys/boot/common/newvers.sh
@@ -32,12 +32,16 @@
#
# @(#)newvers.sh 8.1 (Berkeley) 4/20/94
+tempfile=$(mktemp tmp.XXXXXX) || exit
+trap "rm -f $tempfile" EXIT INT TERM
+
LC_ALL=C; export LC_ALL
u=${USER-root} h=${HOSTNAME-`hostname`} t=`date`
#r=`head -n 6 $1 | tail -n 1 | awk -F: ' { print $1 } '`
r=`awk -F: ' /^[0-9]\.[0-9]+:/ { print $1; exit }' $1`
-echo "char bootprog_name[] = \"FreeBSD/${3} ${2}\";" > vers.c
-echo "char bootprog_rev[] = \"${r}\";" >> vers.c
-echo "char bootprog_date[] = \"${t}\";" >> vers.c
-echo "char bootprog_maker[] = \"${u}@${h}\";" >> vers.c
+echo "char bootprog_name[] = \"FreeBSD/${3} ${2}\";" > $tempfile
+echo "char bootprog_rev[] = \"${r}\";" >> $tempfile
+echo "char bootprog_date[] = \"${t}\";" >> $tempfile
+echo "char bootprog_maker[] = \"${u}@${h}\";" >> $tempfile
+mv $tempfile vers.c
OpenPOWER on IntegriCloud