plugin-loader: Print an error message if plugin constructor is not found

This commit is contained in:
Tobias Brunner
2022-05-06 12:02:45 +02:00
parent 4de8b81dea
commit af9c78d393
+23 -13
View File
@@ -357,19 +357,12 @@ void plugin_constructor_register(char *name, void *constructor)
* FAILED, if the plugin could not be constructed
*/
static status_t create_plugin(private_plugin_loader_t *this, void *handle,
char *name, bool integrity, bool critical,
plugin_entry_t **entry)
char *name, char *create, bool integrity,
bool critical, plugin_entry_t **entry)
{
char create[128];
plugin_t *plugin;
plugin_constructor_t constructor = NULL;
if (snprintf(create, sizeof(create), "%s_plugin_create",
name) >= sizeof(create))
{
return FAILED;
}
translate(create, "-", "_");
#ifdef STATIC_PLUGIN_CONSTRUCTORS
if (plugin_constructors)
{
@@ -416,11 +409,19 @@ static status_t create_plugin(private_plugin_loader_t *this, void *handle,
static plugin_entry_t *load_plugin(private_plugin_loader_t *this, char *name,
char *file, bool critical)
{
char create[128];
plugin_entry_t *entry;
void *handle;
int flag = RTLD_LAZY;
switch (create_plugin(this, RTLD_DEFAULT, name, FALSE, critical, &entry))
if (snprintf(create, sizeof(create), "%s_plugin_create",
name) >= sizeof(create))
{
return NULL;
}
translate(create, "-", "_");
switch (create_plugin(this, RTLD_DEFAULT, name, create, FALSE, critical,
&entry))
{
case SUCCESS:
this->plugins->insert_last(this->plugins, entry);
@@ -430,6 +431,8 @@ static plugin_entry_t *load_plugin(private_plugin_loader_t *this, char *name,
{ /* try to load the plugin from a file */
break;
}
DBG1(DBG_LIB, "plugin '%s': failed to load - %s not found and no "
"plugin file available", name, create);
/* fall-through */
default:
return NULL;
@@ -461,10 +464,17 @@ static plugin_entry_t *load_plugin(private_plugin_loader_t *this, char *name,
DBG1(DBG_LIB, "plugin '%s' failed to load: %s", name, dlerror());
return NULL;
}
if (create_plugin(this, handle, name, TRUE, critical, &entry) != SUCCESS)
switch (create_plugin(this, handle, name, create, TRUE, critical, &entry))
{
dlclose(handle);
return NULL;
case SUCCESS:
break;
case NOT_FOUND:
DBG1(DBG_LIB, "plugin '%s': failed to load - %s not found", name,
create);
/* fall-through */
default:
dlclose(handle);
return NULL;
}
entry->handle = handle;
this->plugins->insert_last(this->plugins, entry);