diff options
author | Felix Fietkau <nbd@nbd.name> | 2025-02-28 17:17:46 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2025-03-06 14:45:29 +0100 |
commit | e04908ef57e79429adfa995461d4630a246e3a2d (patch) | |
tree | 38f8c4d705ce7d86d31bc7013a55db8e165f758f | |
parent | 0c06376cf5f3149900ddab389b033a7c31353a8c (diff) |
uci: add support for altering the override config directory
This was added to libuci recently
Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | lib/uci.c | 20 |
2 files changed, 24 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 858557e..1b7e412 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,6 +202,11 @@ if(UCI_SUPPORT) include_directories(${uci_include_dir}) set(LIBRARIES ${LIBRARIES} uci_lib) add_library(uci_lib MODULE lib/uci.c) + list(APPEND CMAKE_REQUIRED_LIBRARIES ${libubox} ${libuci}) + check_function_exists(uci_set_conf2dir HAVE_UCI_CONF2DIR) + if (HAVE_UCI_CONF2DIR) + target_compile_definitions(uci_lib PUBLIC HAVE_UCI_CONF2DIR) + endif() set_target_properties(uci_lib PROPERTIES OUTPUT_NAME uci PREFIX "") target_link_options(uci_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) target_link_libraries(uci_lib ${libuci} ${libubox}) @@ -151,6 +151,13 @@ uc_uci_error(uc_vm_t *vm, size_t nargs) * uncommitted application changes from the uci cli or other processes on the * system. * + * @param {string} [config2_dir=/var/run/uci] + * The directory to keep override config files in. Files are in the same format + * as in config_dir, but can individually override ones from that directory. + * It defaults to the uci configuration directory `/var/run/uci` but may be + * set to a different path for special purpose applications, or even disabled + * by setting this parameter to an empty string. + * * @returns {?module:uci.cursor} */ static uc_value_t * @@ -158,11 +165,13 @@ uc_uci_cursor(uc_vm_t *vm, size_t nargs) { uc_value_t *cdir = uc_fn_arg(0); uc_value_t *sdir = uc_fn_arg(1); + uc_value_t *c2dir = uc_fn_arg(2); struct uci_context *c; int rv; if ((cdir && ucv_type(cdir) != UC_STRING) || - (sdir && ucv_type(sdir) != UC_STRING)) + (sdir && ucv_type(sdir) != UC_STRING) || + (c2dir && ucv_type(c2dir) != UC_STRING)) err_return(UCI_ERR_INVAL); c = uci_alloc_context(); @@ -184,6 +193,15 @@ uc_uci_cursor(uc_vm_t *vm, size_t nargs) err_return(rv); } +#ifdef HAVE_UCI_CONF2DIR + if (c2dir) { + rv = uci_set_conf2dir(c, ucv_string_get(c2dir)); + + if (rv) + err_return(rv); + } +#endif + ok_return(ucv_resource_create(vm, "uci.cursor", c)); } |