#include <stdlib.h>
#include <unistd.h>
#include <uci.h>
-#include <stdbool.h>
-#include "log.h"
#include "config.h"
+#include "log.h"
static int uci_create_named_section(struct uci_context *ctx,
const char *conf_file_name,
const char *section_type,
- const char *section_name,
- bool save_immediately)
+ const char *section_name)
{
struct uci_ptr ptr;
int ret_val;
if (uci_lookup_ptr(ctx, &ptr, cmd_data, true) == UCI_OK) {
ret_val = uci_set(ctx, &ptr);
if (ret_val == UCI_OK) {
- if (save_immediately) {
- ret_val = uci_save(ctx, ptr.p);
- }
+ ret_val = uci_save(ctx, ptr.p);
}
}
free(cmd_data);
const char *section_type,
const char *section_name,
const char *key,
- const char *value,
- bool save_immediately) {
+ const char *value) {
struct uci_context *ctx;
struct uci_package *pkg;
struct uci_section *sct;
err_flg = uci_create_named_section(ctx,
conf_file_name,
section_type,
- section_name,
- false);
+ section_name);
if (err_flg == UCI_OK) {
uci_foreach_element(&pkg->sections, elem) {
tmp_sct = uci_to_section(elem);
ptr.value = value;
err_flg = uci_set(ctx, &ptr);
if (err_flg == UCI_OK) {
- if (save_immediately == true) {
- err_flg = uci_save(ctx, pkg);
- if (err_flg != UCI_OK) {
- log_error("Failed to set value to configuration file: %s\n. Could not save the file\n", fname);
- }
- }
+ 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);
+ }
+
}
else {
log_error("Failed to set value to configuration file: %s\n. Could not set new value\n", fname);