=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/xinstall/xinstall.c,v retrieving revision 1.70 retrieving revision 1.71 diff -c -r1.70 -r1.71 *** src/usr.bin/xinstall/xinstall.c 2019/02/14 11:50:00 1.70 --- src/usr.bin/xinstall/xinstall.c 2019/02/14 11:51:42 1.71 *************** *** 1,4 **** ! /* $OpenBSD: xinstall.c,v 1.70 2019/02/14 11:50:00 espie Exp $ */ /* $NetBSD: xinstall.c,v 1.9 1995/12/20 10:25:17 jonathan Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: xinstall.c,v 1.71 2019/02/14 11:51:42 espie Exp $ */ /* $NetBSD: xinstall.c,v 1.9 1995/12/20 10:25:17 jonathan Exp $ */ /* *************** *** 222,227 **** --- 222,228 ---- struct timespec ts[2]; int devnull, from_fd, to_fd, serrno, files_match = 0; char *p; + char *target_name = tempfile; (void)memset((void *)&from_sb, 0, sizeof(from_sb)); (void)memset((void *)&to_sb, 0, sizeof(to_sb)); *************** *** 311,320 **** } else { files_match = 1; (void)unlink(tempfile); } } ! (void)close(to_fd); ! to_fd = temp_fd; } /* --- 312,325 ---- } else { files_match = 1; (void)unlink(tempfile); + target_name = to_name; + (void)close(temp_fd); } } ! if (!files_match) { ! (void)close(to_fd); ! to_fd = temp_fd; ! } } /* *************** *** 333,345 **** if ((gid != (gid_t)-1 || uid != (uid_t)-1) && fchown(to_fd, uid, gid)) { serrno = errno; ! (void)unlink(tempfile); ! errx(1, "%s: chown/chgrp: %s", tempfile, strerror(serrno)); } if (fchmod(to_fd, mode)) { serrno = errno; ! (void)unlink(tempfile); ! errx(1, "%s: chmod: %s", tempfile, strerror(serrno)); } /* --- 338,352 ---- if ((gid != (gid_t)-1 || uid != (uid_t)-1) && fchown(to_fd, uid, gid)) { serrno = errno; ! if (target_name == tempfile) ! (void)unlink(target_name); ! errx(1, "%s: chown/chgrp: %s", target_name, strerror(serrno)); } if (fchmod(to_fd, mode)) { serrno = errno; ! if (target_name == tempfile) ! (void)unlink(target_name); ! errx(1, "%s: chmod: %s", target_name, strerror(serrno)); } /* *************** *** 349,355 **** if (fchflags(to_fd, flags & SETFLAGS ? fset : from_sb.st_flags & ~UF_NODUMP)) { if (errno != EOPNOTSUPP || (from_sb.st_flags & ~UF_NODUMP) != 0) ! warnx("%s: chflags: %s", tempfile, strerror(errno)); } if (flags & USEFSYNC) --- 356,362 ---- if (fchflags(to_fd, flags & SETFLAGS ? fset : from_sb.st_flags & ~UF_NODUMP)) { if (errno != EOPNOTSUPP || (from_sb.st_flags & ~UF_NODUMP) != 0) ! warnx("%s: chflags: %s", target_name, strerror(errno)); } if (flags & USEFSYNC)