-
Notifications
You must be signed in to change notification settings - Fork 3
RDKEMW-11792 : FFV config file isolation #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
d94e829
0222245
9453e90
05dd81b
2e08dac
8596bd5
8f6e420
ee2927e
fb60c5d
2688e3d
55bb010
6b92eb4
6a2e3f8
70e9853
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,7 +54,7 @@ ctrlm_config_t::~ctrlm_config_t() { | |
| } | ||
| } | ||
|
|
||
| bool ctrlm_config_t::load_config(const std::string &file_path) { | ||
| bool ctrlm_config_t::load_config(const std::string &file_path, bool verbose) { | ||
| bool ret = false; | ||
| std::string contents = file_to_string(file_path); | ||
| if(this->root) { | ||
|
|
@@ -63,20 +63,60 @@ bool ctrlm_config_t::load_config(const std::string &file_path) { | |
| } | ||
| if(!contents.empty()) { | ||
| json_error_t json_error; | ||
| XLOGD_INFO_OPTS(XLOG_OPTS_DEFAULT, 20 * 1024, "Loading Configuration for <%s> <%s>", file_path.c_str(), contents.c_str()); | ||
| if(verbose) { | ||
| XLOGD_INFO_OPTS(XLOG_OPTS_DEFAULT, 20 * 1024, "Loading Configuration for <%s> <%s>", file_path.c_str(), contents.c_str()); | ||
| } else { | ||
| XLOGD_INFO("Loading Configuration for <%s>", file_path.c_str()); | ||
| } | ||
| this->root = json_loads(contents.c_str(), JSON_REJECT_DUPLICATES, &json_error); | ||
| if(this->root != NULL) { | ||
| XLOGD_INFO("config loaded successfully as JSON"); | ||
| if(verbose) { | ||
| XLOGD_INFO("config loaded successfully as JSON for <%s>", file_path.c_str()); | ||
| } | ||
| ret = true; | ||
| } else { | ||
| XLOGD_ERROR("JSON ERROR: Line <%u> Column <%u> Text <%s>", json_error.line, json_error.column, json_error.text); | ||
| XLOGD_ERROR("JSON ERROR: Line <%u> Column <%u> Text <%s> Contents <%s>", json_error.line, json_error.column, json_error.text, contents.c_str()); | ||
| } | ||
|
Comment on lines
+78
to
79
|
||
| } else { | ||
| XLOGD_ERROR("no config file contents"); | ||
| } | ||
| return(ret); | ||
| } | ||
|
|
||
| bool ctrlm_config_t::append_config(const std::string &file_path, bool verbose) { | ||
| if(this->root == NULL) { | ||
| XLOGD_ERROR("no config file loaded"); | ||
| return(false); | ||
| } | ||
| bool ret = false; | ||
| std::string contents = file_to_string(file_path); | ||
| if(contents.empty()) { | ||
| XLOGD_ERROR("no config file contents"); | ||
| } else { | ||
| json_error_t json_error; | ||
| if(verbose) { | ||
| XLOGD_INFO_OPTS(XLOG_OPTS_DEFAULT, 20 * 1024, "Appending Configuration for <%s> <%s>", file_path.c_str(), contents.c_str()); | ||
| } else { | ||
| XLOGD_INFO("Appending Configuration for <%s>", file_path.c_str()); | ||
| } | ||
| json_t *append_root = json_loads(contents.c_str(), JSON_REJECT_DUPLICATES, &json_error); | ||
| if(append_root == NULL) { | ||
| XLOGD_ERROR("JSON ERROR: Line <%u> Column <%u> Text <%s> Contents <%s>", json_error.line, json_error.column, json_error.text, contents.c_str()); | ||
| } else { | ||
| if(json_object_update(this->root, append_root) != 0) { | ||
| XLOGD_ERROR("Failed to merge JSON objects"); | ||
| } else { | ||
| if(verbose) { | ||
| XLOGD_INFO("config appended successfully as JSON for <%s>", file_path.c_str()); | ||
| } | ||
| ret = true; | ||
| } | ||
| json_decref(append_root); | ||
|
Comment on lines
+102
to
+114
|
||
| } | ||
| } | ||
| return(ret); | ||
| } | ||
|
|
||
| bool ctrlm_config_t::path_exists(const std::string &path) { | ||
| return(ctrlm_utils_json_from_path(this->root, path, false) != NULL ? true : false); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1601,8 +1601,7 @@ gboolean ctrlm_load_authservice_data(void) { | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| gboolean ctrlm_load_config(json_t **json_obj_root, json_t **json_obj_net_rf4ce, json_t **json_obj_voice, json_t **json_obj_device_update, json_t **json_obj_validation, json_t **json_obj_vsdk) { | ||||||||||||||||||||||||||
| std::string config_fn_opt = "/opt/ctrlm_config.json"; | ||||||||||||||||||||||||||
| std::string config_fn_etc = "/etc/ctrlm_config.json"; | ||||||||||||||||||||||||||
| std::string config_fn_etc_override = "/etc/ctrlm_config.json.OVERRIDE"; | ||||||||||||||||||||||||||
| std::string config_fn_oem = "/etc/vendor/input/ctrlm_config.json"; | ||||||||||||||||||||||||||
| json_t *json_obj_ctrlm; | ||||||||||||||||||||||||||
| ctrlm_config_t *ctrlm_config = ctrlm_config_t::get_instance(); | ||||||||||||||||||||||||||
| gboolean local_conf = false; | ||||||||||||||||||||||||||
|
|
@@ -1612,18 +1611,44 @@ gboolean ctrlm_load_config(json_t **json_obj_root, json_t **json_obj_net_rf4ce, | |||||||||||||||||||||||||
| if(ctrlm_config == NULL) { | ||||||||||||||||||||||||||
| XLOGD_ERROR("Failed to get config manager instance"); | ||||||||||||||||||||||||||
| return(false); | ||||||||||||||||||||||||||
| } else if(!ctrlm_is_production_build() && g_file_test(config_fn_opt.c_str(), G_FILE_TEST_EXISTS) && ctrlm_config->load_config(config_fn_opt)) { | ||||||||||||||||||||||||||
| XLOGD_INFO("Read configuration from <%s>", config_fn_opt.c_str()); | ||||||||||||||||||||||||||
| local_conf = true; | ||||||||||||||||||||||||||
| } else if(g_file_test(config_fn_etc.c_str(), G_FILE_TEST_EXISTS) && ctrlm_config->load_config(config_fn_etc)) { | ||||||||||||||||||||||||||
| XLOGD_INFO("Read configuration from <%s>", config_fn_etc.c_str()); | ||||||||||||||||||||||||||
| } else if(g_file_test(config_fn_etc_override.c_str(), G_FILE_TEST_EXISTS) && ctrlm_config->load_config(config_fn_etc_override)) { | ||||||||||||||||||||||||||
| XLOGD_INFO("Read configuration from <%s>", config_fn_etc_override.c_str()); | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| XLOGD_WARN("Configuration error. Configuration file(s) missing, using defaults"); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
dwolaver marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
| bool oem_append = g_file_test(config_fn_oem.c_str(), G_FILE_TEST_EXISTS); | ||||||||||||||||||||||||||
| bool opt_append = ctrlm_is_production_build() ? false : g_file_test(config_fn_opt.c_str(), G_FILE_TEST_EXISTS); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if(!oem_append && !opt_append) { | ||||||||||||||||||||||||||
| XLOGD_INFO("Using default configuration"); | ||||||||||||||||||||||||||
| return(false); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Check for OEM config file override | ||||||||||||||||||||||||||
| if(oem_append) { | ||||||||||||||||||||||||||
| XLOGD_INFO("Loading OEM configuration from <%s>", config_fn_oem.c_str()); | ||||||||||||||||||||||||||
| if(!ctrlm_config->load_config(config_fn_oem)) { | ||||||||||||||||||||||||||
| XLOGD_ERROR("Failed to load OEM configuration from <%s>", config_fn_oem.c_str()); | ||||||||||||||||||||||||||
| return(false); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Check for OPT config file override | ||||||||||||||||||||||||||
| if(opt_append) { | ||||||||||||||||||||||||||
| if(!oem_append) { | ||||||||||||||||||||||||||
| XLOGD_INFO("Loading OPT configuration from <%s>", config_fn_opt.c_str()); | ||||||||||||||||||||||||||
| if(!ctrlm_config->load_config(config_fn_opt)) { | ||||||||||||||||||||||||||
| XLOGD_ERROR("Failed to load OPT configuration from <%s>", config_fn_opt.c_str()); | ||||||||||||||||||||||||||
| return(false); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| XLOGD_INFO("Appending OPT configuration from <%s>", config_fn_opt.c_str()); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
dwolaver marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
| if(!ctrlm_config->append_config(config_fn_opt)) { | ||||||||||||||||||||||||||
| XLOGD_ERROR("Failed to append OPT configuration from <%s>", config_fn_opt.c_str()); | ||||||||||||||||||||||||||
| return(false); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| local_conf = true; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Parse the JSON data | ||||||||||||||||||||||||||
| *json_obj_root = ctrlm_config->json_from_path("", true); // Get root AND add ref to it, since this code derefs it | ||||||||||||||||||||||||||
| if(*json_obj_root == NULL) { | ||||||||||||||||||||||||||
|
|
@@ -1637,24 +1662,36 @@ gboolean ctrlm_load_config(json_t **json_obj_root, json_t **json_obj_net_rf4ce, | |||||||||||||||||||||||||
| return(false); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Print the configuration since it was loaded from files | ||||||||||||||||||||||||||
| char *json_dump = json_dumps(*json_obj_root, JSON_INDENT(3) | JSON_SORT_KEYS); | ||||||||||||||||||||||||||
| if(json_dump == NULL) { | ||||||||||||||||||||||||||
| XLOGD_ERROR("unable to dump JSON object"); | ||||||||||||||||||||||||||
| json_decref(*json_obj_root); | ||||||||||||||||||||||||||
| *json_obj_root = NULL; | ||||||||||||||||||||||||||
| return(false); | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| XLOGD_INFO_OPTS(XLOG_OPTS_DEFAULT, 20 * 1024, "Final configuration:\n%s", json_dump); | ||||||||||||||||||||||||||
| free(json_dump); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+1665
to
+1675
|
||||||||||||||||||||||||||
| // Print the configuration since it was loaded from files | |
| char *json_dump = json_dumps(*json_obj_root, JSON_INDENT(3) | JSON_SORT_KEYS); | |
| if(json_dump == NULL) { | |
| XLOGD_ERROR("unable to dump JSON object"); | |
| json_decref(*json_obj_root); | |
| *json_obj_root = NULL; | |
| return(false); | |
| } else { | |
| XLOGD_INFO_OPTS(XLOG_OPTS_DEFAULT, 20 * 1024, "Final configuration:\n%s", json_dump); | |
| free(json_dump); | |
| } | |
| // Configuration successfully loaded and validated at this point |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the vsdk extraction block immediately below this section, the code sets json_obj_vsdk = NULL when the JSON value is missing or not an object. That only clears the local pointer variable, not the out-param; if the value exists but is the wrong type, callers can still receive a non-object *json_obj_vsdk. Update that branch to clear *json_obj_vsdk instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctrlm_load_config()now loads OEM config from/etc/vendor/input/ctrlm_config.json, but the build installsctrlm_config.jsonto${CMAKE_INSTALL_SYSCONFDIR}(typically/etc). This mismatch means the installed config may never be read at runtime. Align the install destination with the runtime search path (or update the runtime path to match the install).