[PATCH 3/4] saveenv: Properly detect write errors
Sascha Hauer
s.hauer at pengutronix.de
Wed Apr 9 00:39:25 PDT 2014
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 at pengutronix.de>
---
common/environment.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/common/environment.c b/common/environment.c
index 9f4e098..bf813b4 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -201,11 +201,16 @@ 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);
+
+ while (size) {
+ ssize_t now = write(envfd, buf, size);
+ if (now < 0) {
+ ret = -errno;
+ goto out;
+ }
+
+ size -= now;
}
ret = 0;
--
1.9.1
More information about the barebox
mailing list