diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1996-08-14 16:23:56 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1996-08-14 16:23:56 +0000 |
commit | 919ec1760ed29cc2d45cd51f2bccd493285acd96 (patch) | |
tree | 34f5c1be2776b4631b5f38655e90e714f79b9a6a /usr.bin/xinstall/xinstall.c | |
parent | c0e743298457612ec5d85e075ae976a9c45f06be (diff) |
Clean up target/tempfile if mmap or write fails (like non-mmap version)
Diffstat (limited to 'usr.bin/xinstall/xinstall.c')
-rw-r--r-- | usr.bin/xinstall/xinstall.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index df078f40120..62b0d922c53 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xinstall.c,v 1.5 1996/08/08 20:49:26 millert Exp $ */ +/* $OpenBSD: xinstall.c,v 1.6 1996/08/14 16:23:55 millert Exp $ */ /* $NetBSD: xinstall.c,v 1.9 1995/12/20 10:25:17 jonathan Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)xinstall.c 8.1 (Berkeley) 7/21/93"; #endif -static char rcsid[] = "$OpenBSD: xinstall.c,v 1.5 1996/08/08 20:49:26 millert Exp $"; +static char rcsid[] = "$OpenBSD: xinstall.c,v 1.6 1996/08/14 16:23:55 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -414,11 +414,18 @@ copy(from_fd, from_name, to_fd, to_name, size) */ if (size <= 8 * 1048576) { if ((p = mmap(NULL, (size_t)size, PROT_READ, - 0, from_fd, (off_t)0)) == (char *)-1) - err(EX_OSERR, "%s", from_name); + 0, from_fd, (off_t)0)) == (char *)-1) { + serrno = errno; + (void)unlink(to_name); + errx(EX_OSERR, "%s: %s", from_name, strerror(serrno)); + } siz = (size_t)size; - if (write(to_fd, p, siz) != siz) - err(EX_OSERR, "%s", to_name); + if ((nw = write(to_fd, p, siz)) != siz) { + serrno = errno; + (void)unlink(to_name); + errx(EX_OSERR, "%s: %s", + to_name, strerror(nw > 0 ? EIO : serrno)); + } (void) munmap(p, (size_t)size); } else { while ((nr = read(from_fd, buf, sizeof(buf))) > 0) |