From 8da2fd3564518808baaf3d4003db82510a542fc7 Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Fri, 11 Sep 2020 15:32:40 +0100 Subject: [PATCH] db config: get config path in init call --- dmentry.c | 1 + libbbf_api/dmuci.c | 10 ++++++++-- libbbf_api/dmuci.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dmentry.c b/dmentry.c index 1da81d4b..5c21cb0b 100644 --- a/dmentry.c +++ b/dmentry.c @@ -123,6 +123,7 @@ static int dm_ctx_init_custom(struct dmctx *ctx, unsigned int dm_type, unsigned uci_ctx = uci_alloc_context(); uci_varstate_ctx = uci_alloc_context(); DMUCI_INIT(bbfdm); + get_db_config_path(); } INIT_LIST_HEAD(&ctx->list_parameter); INIT_LIST_HEAD(&ctx->set_list_tmp); diff --git a/libbbf_api/dmuci.c b/libbbf_api/dmuci.c index dc412f93..3b05b4cb 100644 --- a/libbbf_api/dmuci.c +++ b/libbbf_api/dmuci.c @@ -18,6 +18,7 @@ struct uci_context *uci_ctx; struct uci_context *uci_varstate_ctx; +static char *db_config = NULL; NEW_UCI_PATH(bbfdm, BBFDM_CONFIG, BBFDM_SAVEDIR) struct uci_section *dmuci_walk_state_section (char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk) @@ -259,11 +260,16 @@ end: return o; } +void get_db_config_path(void) +{ + db_config = (folder_exists(LIB_DB_CONFIG)) ? LIB_DB_CONFIG : ETC_DB_CONFIG; +} + int db_get_value_string(char *package, char *section, char *option, char **value) { struct uci_option *o; - o = dmuci_get_option_ptr((folder_exists(LIB_DB_CONFIG)) ? LIB_DB_CONFIG : ETC_DB_CONFIG, package, section, option); + o = dmuci_get_option_ptr((db_config) ? db_config : LIB_DB_CONFIG, package, section, option); if (o) { *value = o->v.string ? dmstrdup(o->v.string) : ""; // MEM WILL BE FREED IN DMMEMCLEAN } else { @@ -278,7 +284,7 @@ int db_get_value_list(char *package, char *section, char *option, struct uci_lis struct uci_option *o; *value = NULL; - o = dmuci_get_option_ptr((folder_exists(LIB_DB_CONFIG)) ? LIB_DB_CONFIG : ETC_DB_CONFIG, package, section, option); + o = dmuci_get_option_ptr((db_config) ? db_config : LIB_DB_CONFIG, package, section, option); if (o) { *value = &o->v.list; } else { diff --git a/libbbf_api/dmuci.h b/libbbf_api/dmuci.h index d0d6bda9..3282ad56 100644 --- a/libbbf_api/dmuci.h +++ b/libbbf_api/dmuci.h @@ -158,6 +158,7 @@ int dmuci_get_option_value_string(char *package, char *section, char *option, ch char *dmuci_get_option_value_fallback_def(char *package, char *section, char *option, char *default_value); int dmuci_get_option_value_list(char *package, char *section, char *option, struct uci_list **value); struct uci_option *dmuci_get_option_ptr(char *cfg_path, char *package, char *section, char *option); +void get_db_config_path(void); int db_get_value_string(char *package, char *section, char *option, char **value); int db_get_value_list(char *package, char *section, char *option, struct uci_list **value); int dmuci_get_varstate_string(char *package, char *section, char *option, char **value);