summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2008-09-25 18:24:18 +0000
committerFelix Fietkau <nbd@openwrt.org>2008-09-25 18:24:18 +0000
commit5a0a3cbc0016743e4092b7b21b3f6fddf63a8bde (patch)
tree9880bf7a41af8ed37680aa1f5b2adc79ea048ce5 /package
parentd58b9ba0d0106346328442a9d76b3ea8c498b1ac (diff)
downloadmtk-20170518-5a0a3cbc0016743e4092b7b21b3f6fddf63a8bde.zip
mtk-20170518-5a0a3cbc0016743e4092b7b21b3f6fddf63a8bde.tar.gz
mtk-20170518-5a0a3cbc0016743e4092b7b21b3f6fddf63a8bde.tar.bz2
mtd: improve support for reading input from a pipe. fixes sysupgrade
SVN-Revision: 12706
Diffstat (limited to 'package')
-rw-r--r--package/mtd/src/mtd.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/package/mtd/src/mtd.c b/package/mtd/src/mtd.c
index 18c3e97..6e430f4 100644
--- a/package/mtd/src/mtd.c
+++ b/package/mtd/src/mtd.c
@@ -246,7 +246,7 @@ static int
mtd_write(int imagefd, const char *mtd)
{
int fd, result;
- size_t r, w, e;
+ ssize_t r, w, e;
fd = mtd_check_open(mtd);
if(fd < 0) {
@@ -263,11 +263,27 @@ mtd_write(int imagefd, const char *mtd)
for (;;) {
/* buffer may contain data already (from trx check) */
- r = read(imagefd, buf + buflen, erasesize - buflen);
- if (r < 0)
- break;
+ do {
+ r = read(imagefd, buf + buflen, erasesize - buflen);
+ if (r < 0) {
+ if ((errno == EINTR) || (errno == EAGAIN))
+ continue;
+ else {
+ perror("read");
+ break;
+ }
+ }
+
+ if (r == 0) {
+ fprintf(stderr, "No more data left\n");
+ break;
+ }
+
+ buflen += r;
+ } while (buflen < erasesize);
- buflen += r;
+ if (buflen == 0)
+ break;
if (jffs2file) {
if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF)) == 0) {
@@ -309,10 +325,6 @@ mtd_write(int imagefd, const char *mtd)
}
w += buflen;
- /* not enough data - eof */
- if (buflen < erasesize)
- break;
-
buflen = 0;
}
if (!quiet)