Date: Mon, 9 Jul 2012 10:33:53 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r238291 - stable/9/usr.bin/xinstall Message-ID: <201207091033.q69AXrii010888@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Mon Jul 9 10:33:53 2012 New Revision: 238291 URL: http://svn.freebsd.org/changeset/base/238291 Log: MFC r237988: Issue proper diagnostic on the short writes, also consider the case of write reporting 0 bytes as short write. Approved by: re (hrs) Modified: stable/9/usr.bin/xinstall/xinstall.c Directory Properties: stable/9/usr.bin/xinstall/ (props changed) Modified: stable/9/usr.bin/xinstall/xinstall.c ============================================================================== --- stable/9/usr.bin/xinstall/xinstall.c Mon Jul 9 10:24:45 2012 (r238290) +++ stable/9/usr.bin/xinstall/xinstall.c Mon Jul 9 10:33:53 2012 (r238291) @@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$"); #include <grp.h> #include <paths.h> #include <pwd.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -670,11 +671,18 @@ copy(int from_fd, const char *from_name, if (size <= 8 * 1048576 && trymmap(from_fd) && (p = mmap(NULL, (size_t)size, PROT_READ, MAP_SHARED, from_fd, (off_t)0)) != (char *)MAP_FAILED) { - if ((nw = write(to_fd, p, size)) != size) { + nw = write(to_fd, p, size); + if (nw != size) { serrno = errno; (void)unlink(to_name); - errno = nw > 0 ? EIO : serrno; - err(EX_OSERR, "%s", to_name); + if (nw >= 0) { + errx(EX_OSERR, + "short write to %s: %jd bytes written, %jd bytes asked to write", + to_name, (uintmax_t)nw, (uintmax_t)size); + } else { + errno = serrno; + err(EX_OSERR, "%s", to_name); + } } done_copy = 1; } @@ -683,8 +691,15 @@ copy(int from_fd, const char *from_name, if ((nw = write(to_fd, buf, nr)) != nr) { serrno = errno; (void)unlink(to_name); - errno = nw > 0 ? EIO : serrno; - err(EX_OSERR, "%s", to_name); + if (nw >= 0) { + errx(EX_OSERR, + "short write to %s: %jd bytes written, %jd bytes asked to write", + to_name, (uintmax_t)nw, + (uintmax_t)size); + } else { + errno = serrno; + err(EX_OSERR, "%s", to_name); + } } if (nr != 0) { serrno = errno;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201207091033.q69AXrii010888>