summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-04-08 17:20:03 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-04-09 17:00:29 +0200
commitaa49d86b2d80687c36897c3b9f91954d8f1ec9b0 (patch)
tree1fb97d40ed53c70c41f4fb4ca71fc1387fb1b68c
parent8d0b6dd4103a1ccd9e03c46cb5cbc8daa72b40ca (diff)
downloadbarebox-aa49d86b2d80687c36897c3b9f91954d8f1ec9b0.tar.gz
saveenv: Properly detect write errors
The return value check of the write call is completely bogus. We check if we have written at minimum sizeof(struct envfs_super) bytes instead of all bytes. Properly check for all bytes written instead and allow write to write less bytes than requested. Do not use write_full because this file is compiled for userspace aswell. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/environment.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/common/environment.c b/common/environment.c
index 9f4e098..c834902 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -167,7 +167,7 @@ int envfs_save(const char *filename, const char *dirname)
struct envfs_super *super;
int envfd, size, ret;
struct action_data data;
- void *buf = NULL;
+ void *buf = NULL, *wbuf;
data.writep = NULL;
data.base = dirname;
@@ -201,11 +201,19 @@ int envfs_save(const char *filename, const char *dirname)
goto out1;
}
- if (write(envfd, buf, size + sizeof(struct envfs_super)) <
- sizeof(struct envfs_super)) {
- perror("write");
- ret = -1; /* FIXME */
- goto out;
+ size += sizeof(struct envfs_super);
+
+ wbuf = buf;
+
+ while (size) {
+ ssize_t now = write(envfd, wbuf, size);
+ if (now < 0) {
+ ret = -errno;
+ goto out;
+ }
+
+ wbuf += now;
+ size -= now;
}
ret = 0;