Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Aug 2016 18:19:02 +0000 (UTC)
From:      Bryan Drewery <bdrewery@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r303929 - head/usr.bin/xinstall
Message-ID:  <201608101819.u7AIJ2HE079357@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bdrewery
Date: Wed Aug 10 18:19:02 2016
New Revision: 303929
URL: https://svnweb.freebsd.org/changeset/base/303929

Log:
  Fix -S with -b not atomically updating the destination file.
  
  With both of these flags, the backup was created via rename(dest, backup)
  followed by rename(tmp, dest).  This left the destination file missing
  for a moment which contradicts the point of -S.
  
  This fixes a race with installworld where PRECIOUSPROG and PRECIOUSLIB
  files (which use -S for installation) would briefly be missing.  In the
  case of installing rtld with parallel installworld it could render an
  error due to not having rtld present to run install/cp in another
  process.
  
  Reported by:	jhb
  Reviewed by:	jhb
  MFC after:	1 week
  Sponsored by:	EMC / Isilon Storage Division
  Differential Revision:	https://reviews.freebsd.org/D7451

Modified:
  head/usr.bin/xinstall/xinstall.c

Modified: head/usr.bin/xinstall/xinstall.c
==============================================================================
--- head/usr.bin/xinstall/xinstall.c	Wed Aug 10 18:18:51 2016	(r303928)
+++ head/usr.bin/xinstall/xinstall.c	Wed Aug 10 18:19:02 2016	(r303929)
@@ -892,11 +892,17 @@ install(const char *from_name, const cha
 			}
 			if (verbose)
 				(void)printf("install: %s -> %s\n", to_name, backup);
-			if (rename(to_name, backup) < 0) {
+			if (unlink(backup) < 0 && errno != ENOENT) {
 				serrno = errno;
 				unlink(tempfile);
 				errno = serrno;
-				err(EX_OSERR, "rename: %s to %s", to_name,
+				err(EX_OSERR, "unlink: %s", backup);
+			}
+			if (link(to_name, backup) < 0) {
+				serrno = errno;
+				unlink(tempfile);
+				errno = serrno;
+				err(EX_OSERR, "link: %s to %s", to_name,
 				     backup);
 			}
 		}



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