summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2012-07-02 09:53:57 +0000
committerkib <kib@FreeBSD.org>2012-07-02 09:53:57 +0000
commit9b048bab457b5fcde53992abb0fc6111239362a6 (patch)
tree3ea1693874bfc31353a917ae872c386a8025db7e /usr.bin
parent80d58366a4513ca8fca67eb0c1f0135a8e12d4fb (diff)
downloadFreeBSD-src-9b048bab457b5fcde53992abb0fc6111239362a6.zip
FreeBSD-src-9b048bab457b5fcde53992abb0fc6111239362a6.tar.gz
Issue proper diagnostic on the short writes, also consider the
case of write reporting 0 bytes as short write. Reported and tested by: adreast MFC after: 1 week
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/xinstall/xinstall.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
index a920f85..583348a 100644
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -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>
@@ -671,11 +672,18 @@ copy(int from_fd, const char *from_name, int to_fd, const char *to_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;
}
@@ -684,8 +692,15 @@ copy(int from_fd, const char *from_name, int to_fd, const char *to_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;
OpenPOWER on IntegriCloud