diff options
author | Denis Kenzior <denkenz@gmail.com> | 2024-04-01 13:48:02 -0700 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2024-04-03 11:42:55 -0500 |
commit | 961445acdc550c387c3da0a77cdea1a2490e3ead (patch) | |
tree | d112e7f95aba2277f2d271c41048494d9944bab8 | |
parent | 5072741ab979f37b88828b8e28f6e87f8e87c4ba (diff) | |
download | ofono-961445acdc550c387c3da0a77cdea1a2490e3ead.tar.gz |
ofono: Add support for ofono main.conf settings
It would be useful to support some oFono wide configuration settings
that can be configured for the system. Introduce a new
__ofono_get_config() function that will obtain the parsed settings file
as a pointer to l_settings. The settings will be parsed from the
configuration directory set using CONFIGURATION_DIRECTORY environment
variable, or the default CONFIGDIR variable set during
configuration/compilation.
-rw-r--r-- | src/main.c | 32 | ||||
-rw-r--r-- | src/ofono.h | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c index 141853eef..70f4c5278 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,12 @@ #define SHUTDOWN_GRACE_SECONDS 10 static GMainLoop *event_loop; +static struct l_settings *ofono_config; + +const struct l_settings *__ofono_get_config(void) +{ + return ofono_config; +} void __ofono_exit(void) { @@ -204,6 +210,9 @@ int main(int argc, char **argv) DBusError error; guint signal; struct ell_event_source *source; + const char *config_dir; + char **config_dirs; + unsigned int i; context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); @@ -254,6 +263,27 @@ int main(int argc, char **argv) __ofono_log_init(argv[0], option_debug, option_detach); + config_dir = getenv("CONFIGURATION_DIRECTORY"); + if (!config_dir) + config_dir = CONFIGDIR; + + l_debug("Using configuration directory: %s", config_dir); + config_dirs = l_strsplit(config_dir, ':'); + ofono_config = l_settings_new(); + + for (i = 0; config_dirs[i]; i++) { + _auto_(l_free) char *path = l_strdup_printf("%s/main.conf", + config_dirs[i]); + + if (!l_settings_load_from_file(ofono_config, path)) + continue; + + l_info("Loaded configuration from %s", path); + break; + } + + l_strv_free(config_dirs); + dbus_error_init(&error); conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, OFONO_SERVICE, &error); @@ -292,6 +322,8 @@ fail_module_init: dbus_connection_unref(conn); cleanup: + l_settings_free(ofono_config); + g_source_remove(signal); g_source_destroy((GSource *) source); diff --git a/src/ofono.h b/src/ofono.h index 294e90a37..80add8351 100644 --- a/src/ofono.h +++ b/src/ofono.h @@ -26,6 +26,7 @@ #include <ofono/types.h> +const struct l_settings *__ofono_get_config(void); void __ofono_exit(void); int __ofono_handsfree_audio_manager_init(void); |