From owner-svn-src-stable@freebsd.org Fri Aug 19 16:56:53 2016 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B054EBBFC73; Fri, 19 Aug 2016 16:56:53 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7D541153D; Fri, 19 Aug 2016 16:56:53 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7JGuqrN007122; Fri, 19 Aug 2016 16:56:52 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7JGuqsD007121; Fri, 19 Aug 2016 16:56:52 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201608191656.u7JGuqsD007121@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Fri, 19 Aug 2016 16:56:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r304469 - stable/11/usr.bin/xinstall X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Aug 2016 16:56:53 -0000 Author: bdrewery Date: Fri Aug 19 16:56:52 2016 New Revision: 304469 URL: https://svnweb.freebsd.org/changeset/base/304469 Log: MFC r303929,r303930,r303931,r303932,r303933: r303929: Fix -S with -b not atomically updating the destination file. r303930: Support -v for -l. r303931: Fix -S with -l not being atomic. r303932: Fix -b failure not restoring flags on the destination file. r303933: Squelch a false-positive Clang static analyzer warning. Modified: stable/11/usr.bin/xinstall/xinstall.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/xinstall/xinstall.c ============================================================================== --- stable/11/usr.bin/xinstall/xinstall.c Fri Aug 19 16:45:21 2016 (r304468) +++ stable/11/usr.bin/xinstall/xinstall.c Fri Aug 19 16:56:52 2016 (r304469) @@ -149,6 +149,7 @@ main(int argc, char *argv[]) char *p; const char *to_name; + fset = 0; iflags = 0; group = owner = NULL; while ((ch = getopt(argc, argv, "B:bCcD:df:g:h:l:M:m:N:o:pSsT:Uv")) != @@ -533,7 +534,9 @@ do_link(const char *from_name, const cha if (target_sb->st_flags & NOCHANGEBITS) (void)chflags(to_name, target_sb->st_flags & ~NOCHANGEBITS); - unlink(to_name); + if (verbose) + printf("install: link %s -> %s\n", + from_name, to_name); ret = rename(tmpl, to_name); /* * If rename has posix semantics, then the temporary @@ -543,8 +546,12 @@ do_link(const char *from_name, const cha (void)unlink(tmpl); } return (ret); - } else + } else { + if (verbose) + printf("install: link %s -> %s\n", + from_name, to_name); return (link(from_name, to_name)); + } } /* @@ -573,14 +580,18 @@ do_symlink(const char *from_name, const if (target_sb->st_flags & NOCHANGEBITS) (void)chflags(to_name, target_sb->st_flags & ~NOCHANGEBITS); - unlink(to_name); - + if (verbose) + printf("install: symlink %s -> %s\n", + from_name, to_name); if (rename(tmpl, to_name) == -1) { /* Remove temporary link before exiting. */ (void)unlink(tmpl); err(EX_OSERR, "%s: rename", to_name); } } else { + if (verbose) + printf("install: symlink %s -> %s\n", + from_name, to_name); if (symlink(from_name, to_name) == -1) err(EX_OSERR, "symlink %s -> %s", from_name, to_name); } @@ -886,11 +897,21 @@ 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; + if (to_sb.st_flags & NOCHANGEBITS) + (void)chflags(to_name, to_sb.st_flags); + unlink(tempfile); + errno = serrno; + err(EX_OSERR, "unlink: %s", backup); + } + if (link(to_name, backup) < 0) { serrno = errno; unlink(tempfile); + if (to_sb.st_flags & NOCHANGEBITS) + (void)chflags(to_name, to_sb.st_flags); errno = serrno; - err(EX_OSERR, "rename: %s to %s", to_name, + err(EX_OSERR, "link: %s to %s", to_name, backup); } } @@ -1111,16 +1132,26 @@ create_newfile(const char *path, int tar if (dobackup) { if ((size_t)snprintf(backup, MAXPATHLEN, "%s%s", - path, suffix) != strlen(path) + strlen(suffix)) + path, suffix) != strlen(path) + strlen(suffix)) { + saved_errno = errno; + if (sbp->st_flags & NOCHANGEBITS) + (void)chflags(path, sbp->st_flags); + errno = saved_errno; errx(EX_OSERR, "%s: backup filename too long", path); + } (void)snprintf(backup, MAXPATHLEN, "%s%s", path, suffix); if (verbose) (void)printf("install: %s -> %s\n", path, backup); - if (rename(path, backup) < 0) + if (rename(path, backup) < 0) { + saved_errno = errno; + if (sbp->st_flags & NOCHANGEBITS) + (void)chflags(path, sbp->st_flags); + errno = saved_errno; err(EX_OSERR, "rename: %s to %s", path, backup); + } } else if (unlink(path) < 0) saved_errno = errno;