From owner-svn-src-stable-8@FreeBSD.ORG Mon Jul 9 10:36:43 2012 Return-Path: Delivered-To: svn-src-stable-8@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id D1887106566B; Mon, 9 Jul 2012 10:36:43 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A252B8FC19; Mon, 9 Jul 2012 10:36:43 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q69Aah7s011355; Mon, 9 Jul 2012 10:36:43 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q69AahaJ011353; Mon, 9 Jul 2012 10:36:43 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201207091036.q69AahaJ011353@svn.freebsd.org> From: Konstantin Belousov Date: Mon, 9 Jul 2012 10:36:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r238292 - stable/8/usr.bin/xinstall X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jul 2012 10:36:44 -0000 Author: kib Date: Mon Jul 9 10:36:43 2012 New Revision: 238292 URL: http://svn.freebsd.org/changeset/base/238292 Log: MFC r237988: Issue proper diagnostic on the short writes, also consider the case of write reporting 0 bytes as short write. Modified: stable/8/usr.bin/xinstall/xinstall.c Directory Properties: stable/8/usr.bin/xinstall/ (props changed) Modified: stable/8/usr.bin/xinstall/xinstall.c ============================================================================== --- stable/8/usr.bin/xinstall/xinstall.c Mon Jul 9 10:33:53 2012 (r238291) +++ stable/8/usr.bin/xinstall/xinstall.c Mon Jul 9 10:36:43 2012 (r238292) @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -675,11 +676,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; } @@ -688,8 +696,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;