summary refs log tree commit diff
path: root/pkgs/tools/networking/ofono/0001-Search-connectors-in-OFONO_PLUGIN_PATH.patch
blob: eb97209a693e47757fde03eb20eea067fd03d034 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
From 0e0994c9716700c9484b3dccb25f98a9a59d1744 Mon Sep 17 00:00:00 2001
From: Jan Tojnar <jtojnar@gmail.com>
Date: Fri, 23 Aug 2019 18:42:51 +0200
Subject: [PATCH] Search connectors in OFONO_PLUGIN_PATH

Previously, the connectors would only be looked for in a single
directory, specified during compilation. This patch allows to
traverse a list of directories provided by an environment variable.
---
 src/plugin.c | 77 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 50 insertions(+), 27 deletions(-)

diff --git a/src/plugin.c b/src/plugin.c
index 924a45ec..f05055c3 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -99,35 +99,12 @@ static gboolean check_plugin(struct ofono_plugin_desc *desc,
 	return TRUE;
 }
 
-#include "builtin.h"
-
-int __ofono_plugin_init(const char *pattern, const char *exclude)
-{
-	gchar **patterns = NULL;
-	gchar **excludes = NULL;
-	GSList *list;
-	GDir *dir;
+static handle_dir(const gchar *plugin_path, const gchar **patterns, const gchar **excludes) {
 	const gchar *file;
 	gchar *filename;
-	unsigned int i;
-
-	DBG("");
-
-	if (pattern)
-		patterns = g_strsplit_set(pattern, ":, ", -1);
-
-	if (exclude)
-		excludes = g_strsplit_set(exclude, ":, ", -1);
-
-	for (i = 0; __ofono_builtin[i]; i++) {
-		if (check_plugin(__ofono_builtin[i],
-					patterns, excludes) == FALSE)
-			continue;
-
-		add_plugin(NULL, __ofono_builtin[i]);
-	}
+	GDir *dir;
 
-	dir = g_dir_open(PLUGINDIR, 0, NULL);
+	dir = g_dir_open(plugin_path, 0, NULL);
 	if (dir != NULL) {
 		while ((file = g_dir_read_name(dir)) != NULL) {
 			void *handle;
@@ -137,7 +114,7 @@ int __ofono_plugin_init(const char *pattern, const char *exclude)
 					g_str_has_suffix(file, ".so") == FALSE)
 				continue;
 
-			filename = g_build_filename(PLUGINDIR, file, NULL);
+			filename = g_build_filename(plugin_path, file, NULL);
 
 			handle = dlopen(filename, RTLD_NOW);
 			if (handle == NULL) {
@@ -168,6 +145,52 @@ int __ofono_plugin_init(const char *pattern, const char *exclude)
 
 		g_dir_close(dir);
 	}
+}
+
+#include "builtin.h"
+
+int __ofono_plugin_init(const char *pattern, const char *exclude)
+{
+	gchar **patterns = NULL;
+	gchar **excludes = NULL;
+	GSList *list;
+	unsigned int i;
+
+	DBG("");
+
+	if (pattern)
+		patterns = g_strsplit_set(pattern, ":, ", -1);
+
+	if (exclude)
+		excludes = g_strsplit_set(exclude, ":, ", -1);
+
+	for (i = 0; __ofono_builtin[i]; i++) {
+		if (check_plugin(__ofono_builtin[i],
+					patterns, excludes) == FALSE)
+			continue;
+
+		add_plugin(NULL, __ofono_builtin[i]);
+	}
+
+
+	const gchar *plugin_path;
+
+	plugin_path = g_getenv ("OFONO_PLUGIN_PATH");
+
+	if (!plugin_path) {
+		gchar **plugin_path_list;
+		gsize i;
+
+		plugin_path_list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
+
+		for (i = 0; plugin_path_list[i]; i++) {
+			handle_dir(plugin_path_list, patterns, excludes);
+		}
+
+		g_strfreev(plugin_path_list);
+	}
+
+	handle_dir(PLUGINDIR, patterns, excludes);
 
 	for (list = plugins; list; list = list->next) {
 		struct ofono_plugin *plugin = list->data;
-- 
2.22.0