diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-04-08 17:20:03 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-04-09 17:00:29 +0200 |
commit | aa49d86b2d80687c36897c3b9f91954d8f1ec9b0 (patch) | |
tree | 1fb97d40ed53c70c41f4fb4ca71fc1387fb1b68c /common | |
parent | 8d0b6dd4103a1ccd9e03c46cb5cbc8daa72b40ca (diff) | |
download | barebox-aa49d86b2d80687c36897c3b9f91954d8f1ec9b0.tar.gz barebox-aa49d86b2d80687c36897c3b9f91954d8f1ec9b0.tar.xz |
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>
Diffstat (limited to 'common')
-rw-r--r-- | common/environment.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/common/environment.c b/common/environment.c index 9f4e098285..c834902727 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; |