diff options
author | Luka Perkov <luka@openwrt.org> | 2014-01-29 11:21:58 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2014-01-29 13:29:48 +0000 |
commit | 835b8b768da374075af56f624537d03d8ec97647 (patch) | |
tree | 3098da72032ba586b5c2c6d2061a54178ccdad49 | |
parent | 11f5072bb197c8571518222f8d6572b66338dc8d (diff) | |
download | rpcd-835b8b768da374075af56f624537d03d8ec97647.tar.gz |
file: when writing a file make sure it's contents are stored
Fixes problems with ubi(fs).
Signed-off-by: Luka Perkov <luka@openwrt.org>
-rw-r--r-- | file.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -214,8 +214,14 @@ rpc_file_write(struct ubus_context *ctx, struct ubus_object *obj, if ((fd = open(blobmsg_data(tb[RPC_F_PATH]), O_CREAT | O_TRUNC | O_WRONLY)) < 0) return rpc_errno_status(); - write(fd, blobmsg_data(tb[RPC_F_DATA]), blobmsg_data_len(tb[RPC_F_DATA])); + if (write(fd, blobmsg_data(tb[RPC_F_DATA]), blobmsg_data_len(tb[RPC_F_DATA])) < 0) + return rpc_errno_status(); + + if (fsync(fd) < 0) + return rpc_errno_status(); + close(fd); + sync(); return 0; } |