Skip to content
Snippets Groups Projects
Commit 40bb7f15 authored by Amin Ben Romdhane's avatar Amin Ben Romdhane
Browse files

Improvment

parent 4250cc04
No related branches found
No related tags found
1 merge request!11Refresh dump output only when the new output is ready
Pipeline #185115 passed
......@@ -283,27 +283,42 @@ static void fwbank_dump_finish_callback(struct ubus_context *ctx, struct ubus_re
close(pipe_fds[0]); // Close read end
if (bytes_read < 0) {
if (bytes_read < 0 || strlen(buffer) == 0) {
BBF_ERR("Failed to read from pipe");
goto retry;
}
free_global_fwbank_dump(&g_fwbank_dump.output);
// Use a temporary blob_buf for validation
struct blob_buf temp_buf = {0};
memset(&g_fwbank_dump.output, 0, sizeof(struct blob_buf));
blob_buf_init(&g_fwbank_dump.output, 0);
memset(&temp_buf, 0, sizeof(struct blob_buf));
blob_buf_init(&temp_buf, 0);
if (!blobmsg_add_json_from_string(&g_fwbank_dump.output, buffer)) {
BBF_ERR("Failed to create blob buf");
goto retry;
if (!blobmsg_add_json_from_string(&temp_buf, buffer)) {
BBF_ERR("Invalid JSON format in buffer");
blob_buf_free(&temp_buf);
goto retry;
}
int res = validate_global_fwbank_dump(&g_fwbank_dump.output);
int res = validate_global_fwbank_dump(&temp_buf);
if (res) {
BBF_ERR("Failed to validate 'fwbank' output");
blob_buf_free(&temp_buf);
goto retry;
}
free_global_fwbank_dump(&g_fwbank_dump.output);
// Init g_fwbank_dump.output
memset(&g_fwbank_dump.output, 0, sizeof(struct blob_buf));
blob_buf_init(&g_fwbank_dump.output, 0);
// Move validated JSON from temp_buf to g_fwbank_dump.output
blobmsg_add_blob(&g_fwbank_dump.output, blob_data(temp_buf.head));
// Free the temporary buffer
blob_buf_free(&temp_buf);
return;
retry:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment