From 2f3a0805b0a4b7cc3cb6188d467ec4a2a7071f36 Mon Sep 17 00:00:00 2001 From: Suvendhu Hansa Date: Thu, 4 Sep 2025 18:56:38 +0530 Subject: [PATCH] rename unnamed dmmap section --- libbbfdm-api/legacy/dmcommon.c | 10 +++++++++ libbbfdm/device.c | 38 +++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/libbbfdm-api/legacy/dmcommon.c b/libbbfdm-api/legacy/dmcommon.c index e4e4dd24..49fa4a71 100644 --- a/libbbfdm-api/legacy/dmcommon.c +++ b/libbbfdm-api/legacy/dmcommon.c @@ -430,12 +430,22 @@ void synchronize_specific_config_sections_with_dmmap(const char *package, const char *v = NULL; uci_foreach_sections(package, section_type, s) { + char sec_name[64] = {0}; + + snprintf(sec_name, sizeof(sec_name), "%s_%s", section_type, section_name(s)); + /* * create/update corresponding dmmap section that have same config_section link and using param_value_array */ if ((dmmap_sect = get_dup_section_in_dmmap(dmmap_package, section_type, section_name(s))) == NULL) { dmuci_add_section_bbfdm(dmmap_package, section_type, &dmmap_sect); + dmuci_rename_section_by_section(dmmap_sect, sec_name); dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(s)); + } else { + const char *reg_exp = "^cfg[0-9a-fA-F]{6}$"; + if (match(section_name(dmmap_sect), reg_exp, 0, NULL) == true) { + dmuci_rename_section_by_section(dmmap_sect, sec_name); + } } /* diff --git a/libbbfdm/device.c b/libbbfdm/device.c index d601bc85..fc898b64 100644 --- a/libbbfdm/device.c +++ b/libbbfdm/device.c @@ -20,33 +20,51 @@ **************************************************************/ static void _exec_reboot(const void *arg1, void *arg2) { - char config_name[16] = {0}; + struct bbfdm_ctx d_ctx = {0}; + struct blob_buf bb = {0}; - snprintf(config_name, sizeof(config_name), "%s", "sysmngr"); + bbfdm_init_ctx(&d_ctx); + memset(&bb, 0, sizeof(struct blob_buf)); + blob_buf_init(&bb, 0); // Set last_reboot_cause to 'RemoteReboot' because the upcoming reboot will be initiated by USP Operate - dmuci_set_value(config_name, "reboots", "last_reboot_cause", "RemoteReboot"); - dmuci_commit_package(config_name); - + bbfdm_uci_set(&d_ctx, "sysmngr", "reboots", "last_reboot_cause", "RemoteReboot"); + bbfdm_uci_commit_package(&d_ctx, "sysmngr"); sleep(3); - dmubus_call_set("rpc-sys", "reboot", UBUS_ARGS{0}, 0); + + bbfdm_ubus_invoke_sync(&d_ctx, "rpc-sys", "reboot", bb.head, 5000, NULL, NULL); sleep(30); // Wait for reboot to happen + BBF_ERR("Reboot call failed with rpc-sys, trying again with system"); - dmubus_call_set("system", "reboot", UBUS_ARGS{0}, 0); + bbfdm_ubus_invoke_sync(&d_ctx, "system", "reboot", bb.head, 5000, NULL, NULL); sleep(30); // Wait for reboot + BBF_ERR("Reboot call failed!!!"); // Set last_reboot_cause to empty because there is a problem in the system reboot - dmuci_set_value(config_name, "reboots", "last_reboot_cause", ""); - dmuci_commit_package(config_name); + bbfdm_uci_set(&d_ctx, "sysmngr", "reboots", "last_reboot_cause", ""); + bbfdm_uci_commit_package(&d_ctx, "sysmngr"); + bbfdm_free_ctx(&d_ctx); + blob_buf_free(&bb); } static void _exec_factoryreset(const void *arg1, void *arg2) { + struct bbfdm_ctx d_ctx = {0}; + struct blob_buf bb = {0}; + + bbfdm_init_ctx(&d_ctx); + memset(&bb, 0, sizeof(struct blob_buf)); + blob_buf_init(&bb, 0); + sleep(2); - dmubus_call_set("rpc-sys", "factory", UBUS_ARGS{0}, 0); + bbfdm_ubus_invoke_sync(&d_ctx, "rpc-sys", "factory", bb.head, 5000, NULL, NULL); sleep(5); // Wait for reboot to happen + BBF_ERR("FactoryReset via rpc-sys failed, trying defaultreset"); + bbfdm_free_ctx(&d_ctx); + blob_buf_free(&bb); + dmcmd_no_wait("/sbin/defaultreset", 0); sleep(5); // Wait for reboot to happen BBF_ERR("FactoryReset call failed!!!");