diff options
author | Alessio Vanni <vannilla@firemail.cc> | 2021-04-04 16:51:09 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2021-04-05 18:15:14 +0200 |
commit | 45720bde1c56c414fec8a1c3d5775208c3b32139 (patch) | |
tree | 74dc74c8d1639c50901320b688bb3cae81d47266 /src/datacache | |
parent | 879cfdc43babb80a0c0618dfe3afa960fbed6e7d (diff) | |
download | gnunet-45720bde1c56c414fec8a1c3d5775208c3b32139.tar.gz gnunet-45720bde1c56c414fec8a1c3d5775208c3b32139.zip |
Implement function to load plugins within a specific context
When `GNUNET_OS_init' is called to change the application project data,
lazy-loading plugins will fail as it will not find the requested files.
The function will temporarily swap the project data with the argument value
and will search for plugins, within the installation directory tree inferred
from that structure.
Applications can still use `GNUNET_PLUGIN_load_all' to load their plugins from
within their own installation directory tree, though services are recommended
to use the `in_context' version to avoid falling in the same pit.
Signed-off-by: Martin Schanzenbach <mschanzenbach@posteo.de>
Diffstat (limited to 'src/datacache')
-rw-r--r-- | src/datacache/datacache.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c index 1ae228b86..5fc5a7481 100644 --- a/src/datacache/datacache.c +++ b/src/datacache/datacache.c | |||
@@ -138,6 +138,7 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
138 | struct GNUNET_DATACACHE_Handle *ret; | 138 | struct GNUNET_DATACACHE_Handle *ret; |
139 | char *libname; | 139 | char *libname; |
140 | char *name; | 140 | char *name; |
141 | const struct GNUNET_OS_ProjectData *pd; | ||
141 | 142 | ||
142 | if (GNUNET_OK != | 143 | if (GNUNET_OK != |
143 | GNUNET_CONFIGURATION_get_value_size (cfg, section, "QUOTA", "a)) | 144 | GNUNET_CONFIGURATION_get_value_size (cfg, section, "QUOTA", "a)) |
@@ -190,14 +191,25 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
190 | GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name); | 191 | GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name); |
191 | ret->short_name = name; | 192 | ret->short_name = name; |
192 | ret->lib_name = libname; | 193 | ret->lib_name = libname; |
194 | /* Load the plugin within GNUnet's default context */ | ||
195 | pd = GNUNET_OS_project_data_get (); | ||
196 | GNUNET_OS_init(GNUNET_OS_project_data_default ()); | ||
193 | ret->api = GNUNET_PLUGIN_load (libname, &ret->env); | 197 | ret->api = GNUNET_PLUGIN_load (libname, &ret->env); |
194 | if (ret->api == NULL) | 198 | GNUNET_OS_init(pd); |
199 | if (NULL == ret->api) | ||
195 | { | 200 | { |
196 | LOG (GNUNET_ERROR_TYPE_ERROR, | 201 | /* Try to load the plugin within the application's context |
197 | _ ("Failed to load datacache plugin for `%s'\n"), | 202 | This normally happens when the application is not GNUnet itself but a |
198 | name); | 203 | third party; inside GNUnet this is effectively a double failure. */ |
199 | GNUNET_DATACACHE_destroy (ret); | 204 | ret->api = GNUNET_PLUGIN_load (libname, &ret->env); |
200 | return NULL; | 205 | if (NULL == ret->api) |
206 | { | ||
207 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
208 | _ ("Failed to load datacache plugin for `%s'\n"), | ||
209 | name); | ||
210 | GNUNET_DATACACHE_destroy (ret); | ||
211 | return NULL; | ||
212 | } | ||
201 | } | 213 | } |
202 | return ret; | 214 | return ret; |
203 | } | 215 | } |