Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Jun 2019 02:37:55 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r349256 - head/libexec/rc/rc.d
Message-ID:  <201906210237.x5L2bt8I012721@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Fri Jun 21 02:37:54 2019
New Revision: 349256
URL: https://svnweb.freebsd.org/changeset/base/349256

Log:
  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

Modified:
  head/libexec/rc/rc.d/motd

Modified: head/libexec/rc/rc.d/motd
==============================================================================
--- head/libexec/rc/rc.d/motd	Fri Jun 21 00:52:30 2019	(r349255)
+++ head/libexec/rc/rc.d/motd	Fri Jun 21 02:37:54 2019	(r349256)
@@ -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 '.'
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201906210237.x5L2bt8I012721>