1 From 0e0994c9716700c9484b3dccb25f98a9a59d1744 Mon Sep 17 00:00:00 2001
2 From: Jan Tojnar <jtojnar@gmail.com>
3 Date: Fri, 23 Aug 2019 18:42:51 +0200
4 Subject: [PATCH] Search connectors in OFONO_PLUGIN_PATH
6 Previously, the connectors would only be looked for in a single
7 directory, specified during compilation. This patch allows to
8 traverse a list of directories provided by an environment variable.
10 src/plugin.c | 77 ++++++++++++++++++++++++++++++++++------------------
11 1 file changed, 50 insertions(+), 27 deletions(-)
13 diff --git a/src/plugin.c b/src/plugin.c
14 index 924a45ec..f05055c3 100644
17 @@ -99,35 +99,12 @@ static gboolean check_plugin(struct ofono_plugin_desc *desc,
23 -int __ofono_plugin_init(const char *pattern, const char *exclude)
25 - gchar **patterns = NULL;
26 - gchar **excludes = NULL;
29 +static handle_dir(const gchar *plugin_path, const gchar **patterns, const gchar **excludes) {
37 - patterns = g_strsplit_set(pattern, ":, ", -1);
40 - excludes = g_strsplit_set(exclude, ":, ", -1);
42 - for (i = 0; __ofono_builtin[i]; i++) {
43 - if (check_plugin(__ofono_builtin[i],
44 - patterns, excludes) == FALSE)
47 - add_plugin(NULL, __ofono_builtin[i]);
51 - dir = g_dir_open(PLUGINDIR, 0, NULL);
52 + dir = g_dir_open(plugin_path, 0, NULL);
54 while ((file = g_dir_read_name(dir)) != NULL) {
56 @@ -137,7 +114,7 @@ int __ofono_plugin_init(const char *pattern, const char *exclude)
57 g_str_has_suffix(file, ".so") == FALSE)
60 - filename = g_build_filename(PLUGINDIR, file, NULL);
61 + filename = g_build_filename(plugin_path, file, NULL);
63 handle = dlopen(filename, RTLD_NOW);
65 @@ -168,6 +145,52 @@ int __ofono_plugin_init(const char *pattern, const char *exclude)
73 +int __ofono_plugin_init(const char *pattern, const char *exclude)
75 + gchar **patterns = NULL;
76 + gchar **excludes = NULL;
83 + patterns = g_strsplit_set(pattern, ":, ", -1);
86 + excludes = g_strsplit_set(exclude, ":, ", -1);
88 + for (i = 0; __ofono_builtin[i]; i++) {
89 + if (check_plugin(__ofono_builtin[i],
90 + patterns, excludes) == FALSE)
93 + add_plugin(NULL, __ofono_builtin[i]);
97 + const gchar *plugin_path;
99 + plugin_path = g_getenv ("OFONO_PLUGIN_PATH");
102 + gchar **plugin_path_list;
105 + plugin_path_list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
107 + for (i = 0; plugin_path_list[i]; i++) {
108 + handle_dir(plugin_path_list, patterns, excludes);
111 + g_strfreev(plugin_path_list);
114 + handle_dir(PLUGINDIR, patterns, excludes);
116 for (list = plugins; list; list = list->next) {
117 struct ofono_plugin *plugin = list->data;