mirror of
https://github.com/troglobit/finit.git
synced 2026-11-06 15:51:03 +00:00
Plugin loader and registration fixes
- Use RTLD_GLOBAL flag to tell dynamic loader to load dependent .so files as well. Also lets other plugins use globally scoped symbols. - Check for plugin hooks as well before dismissing plugin as unused. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
5116cd66ef
commit
3f1c2f6211
1 file changed
+12
-7
@@ -41,7 +41,7 @@ static LIST_HEAD(, plugin) plugins = LIST_HEAD_INITIALIZER();
|
|||||||
|
|
||||||
int plugin_register(plugin_t *plugin)
|
int plugin_register(plugin_t *plugin)
|
||||||
{
|
{
|
||||||
int inuse = 0;
|
int i, inuse = 0;
|
||||||
|
|
||||||
if (!plugin) {
|
if (!plugin) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
@@ -78,8 +78,13 @@ int plugin_register(plugin_t *plugin)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < HOOK_MAX_NUM; i++) {
|
||||||
|
if (plugin->hook[i].cb)
|
||||||
|
inuse++;
|
||||||
|
}
|
||||||
|
|
||||||
if (!inuse) {
|
if (!inuse) {
|
||||||
_e("No service \"%s\" loaded, skipping plugin.", basename(plugin->name));
|
_e("No service \"%s\" loaded, and no I/O or finit hooks, skipping plugin.", basename(plugin->name));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,13 +195,13 @@ int plugin_load_all(char *path)
|
|||||||
|
|
||||||
if (!strcmp(ext, ".so")) {
|
if (!strcmp(ext, ".so")) {
|
||||||
void *handle;
|
void *handle;
|
||||||
char filename[1024];
|
char plugin[1024];
|
||||||
|
|
||||||
snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name);
|
snprintf(plugin, sizeof(plugin), "%s/%s", path, entry->d_name);
|
||||||
print_desc(" Loading plugin ", basename(filename));
|
print_desc(" Loading plugin ", basename(plugin));
|
||||||
handle = dlopen(filename, RTLD_LAZY);
|
handle = dlopen(plugin, RTLD_LAZY | RTLD_GLOBAL);
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
_d("Failed loading plugin %s: %s", filename, dlerror());
|
_d("Failed loading plugin %s: %s", plugin, dlerror());
|
||||||
print_result(1);
|
print_result(1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user