summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2012-09-14 00:00:30 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2012-09-14 00:00:30 +0000
commit8ac76e517e06672437128018dddc076ac3669a69 (patch)
treea70c9493d5e12b9d7452705aa834eda68b407c03 /usr.bin
parent50d20b7957b3ec710e60e5d0c521bc958dc49930 (diff)
There's no reason to unlink the destination if we can't even open
the source file. This fixes a problem with the databases/ruby-ldap port. Note that I changed the O_TRUNC to O_EXCL to avoid the race between unlink/rename and creat. OK naddy@ jeremy@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/xinstall/xinstall.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
index 7a914b75b04..bdf85037423 100644
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xinstall.c,v 1.51 2012/04/11 14:19:35 millert Exp $ */
+/* $OpenBSD: xinstall.c,v 1.52 2012/09/14 00:00:29 millert Exp $ */
/* $NetBSD: xinstall.c,v 1.9 1995/12/20 10:25:17 jonathan Exp $ */
/*
@@ -235,6 +235,11 @@ install(char *from_name, char *to_name, u_long fset, u_int flags)
docompare = 0;
}
+ if (!devnull) {
+ if ((from_fd = open(from_name, O_RDONLY, 0)) < 0)
+ err(EX_OSERR, "%s", from_name);
+ }
+
if (safecopy) {
to_fd = create_tempfile(to_name, tempfile, sizeof(tempfile));
if (to_fd < 0)
@@ -248,12 +253,6 @@ install(char *from_name, char *to_name, u_long fset, u_int flags)
}
if (!devnull) {
- if ((from_fd = open(from_name, O_RDONLY, 0)) < 0) {
- serrno = errno;
- (void)unlink(safecopy ? tempfile : to_name);
- errx(EX_OSERR, "%s: %s", from_name, strerror(serrno));
- }
-
if (docompare && !safecopy) {
files_match = !(compare(from_fd, from_name,
(size_t)from_sb.st_size, to_fd,
@@ -643,7 +642,7 @@ create_newfile(char *path, struct stat *sbp)
} else
(void)unlink(path);
- return(open(path, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR));
+ return(open(path, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR));
}
/*