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>
This commit is contained in:
parent
11f5072bb1
commit
835b8b768d
1 changed files with 7 additions and 1 deletions
8
file.c
8
file.c
|
@ -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)
|
if ((fd = open(blobmsg_data(tb[RPC_F_PATH]), O_CREAT | O_TRUNC | O_WRONLY)) < 0)
|
||||||
return rpc_errno_status();
|
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);
|
close(fd);
|
||||||
|
sync();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue