diff --git a/bbfdmd/ubus/get.c b/bbfdmd/ubus/get.c index 60697b58..fd4109d5 100644 --- a/bbfdmd/ubus/get.c +++ b/bbfdmd/ubus/get.c @@ -850,10 +850,6 @@ void bbfdm_get_value(bbfdm_data_t *data, void *output) ERR("IPC failed for path(%s)", data->bbf_ctx.in_param); } - // Apply all bbfdm changes - if (is_transaction_running() == false) - dmuci_commit_bbfdm(); - if (output) memcpy(output, data->bb.head, blob_pad_len(data->bb.head)); else @@ -899,10 +895,6 @@ void bbfdm_get_names(bbfdm_data_t *data) blobmsg_close_array(&data->bb, array); - // Apply all bbfdm changes - if (is_transaction_running() == false) - dmuci_commit_bbfdm(); - bbf_cleanup(&data->bbf_ctx); } @@ -939,10 +931,6 @@ void bbfdm_get_instances(bbfdm_data_t *data) blobmsg_close_array(&data->bb, array); - // Apply all bbfdm changes - if (is_transaction_running() == false) - dmuci_commit_bbfdm(); - bbf_cleanup(&data->bbf_ctx); } diff --git a/libbbfdm-api/CMakeLists.txt b/libbbfdm-api/CMakeLists.txt index dd7f9b69..75e634ea 100644 --- a/libbbfdm-api/CMakeLists.txt +++ b/libbbfdm-api/CMakeLists.txt @@ -38,3 +38,8 @@ INSTALL(FILES scripts/bbf.secure PERMISSIONS OWNER_EXECUTE DESTINATION usr/libexec/rpcd ) + +INSTALL(FILES scripts/bbf.config + PERMISSIONS OWNER_EXECUTE + DESTINATION usr/libexec/rpcd +) diff --git a/libbbfdm-api/dmentry.c b/libbbfdm-api/dmentry.c index 0d55c756..0473878b 100644 --- a/libbbfdm-api/dmentry.c +++ b/libbbfdm-api/dmentry.c @@ -441,11 +441,10 @@ void bbf_entry_restart_services(struct blob_buf *bb, bool restart_services) if (restart_services) { dmubus_call_set("uci", "commit", UBUS_ARGS{{"config", pc->package, String}}, 1); + dmuci_commit_bbfdm(); } } - dmuci_commit_bbfdm(); - free_all_list_package_change(&head_package_change); } diff --git a/libbbfdm-api/scripts/bbf.config b/libbbfdm-api/scripts/bbf.config new file mode 100755 index 00000000..3e18fae2 --- /dev/null +++ b/libbbfdm-api/scripts/bbf.config @@ -0,0 +1,72 @@ +#!/bin/sh + +. /usr/share/libubox/jshn.sh + +BBFDM_DMMAP_CONFIG="/etc/bbfdm/dmmap" +BBFDM_DMMAP_SAVEDIR="/tmp/.bbfdm" + +check_result() { + local res="$1" + local service="$2" + local action="$3" + + if [ "${res}" -ne 0 ]; then + echo "{ \"error\": \"Failed to ${action} ${service} service\" }" + exit "${res}" + fi +} + +apply_config_changes() { + local service="$1" + local action="$3" + + # Check if either service or action is empty + if [ -z "$service" ] || [ -z "$action" ]; then + return + fi + + logger -t bbf.config -p info "Applying $action configuration for service: $service" + + # Commit/Revert config changes + ubus -t 1 call uci ${action} "{'config': '${service}'}" + check_result "$?" "${service}" "${action}" +} + +case "$1" in + list) + echo '{ "commit": { "services": [] }, "revert": { "services": [] } }' + ;; + call) + # Read input JSON from standard input + read -r input + + # Parse input JSON + json_load "${input}" + + # Check if 'services' array is provided + json_get_type type "services" + if [ -z "${type}" ]; then + echo '{ "error": "Services array should be defined !!!" }' + exit 1 + fi + + # Check if 'services' is array + if [ "${type}" != "array" ]; then + echo '{ "error": "Services argument should be array of strings !!!" }' + exit 1 + fi + + # Iterate over each service and apply config changes + json_for_each_item "apply_config_changes" "services" "$2" + + # Commit/Revert bbfdm dmmap config changes + for file in "${BBFDM_DMMAP_CONFIG}"/*; do + file_name=$(basename "${file}") + logger -t bbf.config -p info "Applying $2 configuration for file: $file_name" + uci -q -c "${BBFDM_DMMAP_CONFIG}" -t "${BBFDM_DMMAP_SAVEDIR}" "$2" "${file_name}" + check_result "$?" "${file_name}" "$2" + done + + echo '{ "status": "ok" }' + ;; +esac