rc.d/motd: Update motd more robustly

Use appropriate fsyncs to persist the rewritten /etc/motd file, when a
rewrite is performed.

Reported by:	Jonathan Walton <jonathan AT isilon.com>
Reviewed by:	allanjude, vangyzen
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D20701
This commit is contained in:
Conrad Meyer 2019-06-21 02:37:54 +00:00
parent 58b5b90d6a
commit cd07b6eddc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=349256

View File

@ -37,11 +37,15 @@ motd_start()
uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
cmp -s $T /etc/motd || {
cp $T /etc/motd
if ! cmp -s $T /etc/motd; then
mv -f $T /etc/.motd.tmp
fsync /etc/.motd.tmp
mv -f /etc/.motd.tmp /etc/motd
chmod ${PERMS} /etc/motd
}
rm -f $T
fsync /etc
else
rm -f $T
fi
check_startmsgs && echo '.'
}