- if (err_flg == 0) {
- opt = uci_lookup_option(ctx, sct, key);
- if (opt != NULL) {
- memset(&ptr, 0, sizeof(ptr));
- ptr.package = pkg->e.name;
- ptr.section = sct->e.name;
- ptr.option = key;
+ if (err_flg == UCI_OK) {
+ memset(&ptr, 0, sizeof(ptr));
+ ptr.package = pkg->e.name;
+ ptr.section = sct->e.name;
+ ptr.option = key;
+ err_flg = uci_lookup_ptr(ctx, &ptr, NULL, false);
+ if (err_flg == UCI_OK) {
+ ptr.value = value;
+ err_flg = uci_set(ctx, &ptr);
+ if (err_flg == UCI_OK) {
+ err_flg = uci_save(ctx, pkg);
+ if (err_flg == UCI_OK) {
+ ret_val = true;
+ log_debug("Set value to section %s in configuration file: %s\n", section_name, fname);
+ }
+ else {
+ log_error("Failed to set value to configuration file: %s\n. Could not save the file\n", fname);
+ }