]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
plugin-loader: Print an error message if plugin constructor is not found
authorTobias Brunner <tobias@strongswan.org>
Thu, 5 May 2022 08:21:10 +0000 (10:21 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 6 May 2022 10:02:45 +0000 (12:02 +0200)
src/libstrongswan/plugins/plugin_loader.c

index 538de2abec2f84880fae79a76357b4a1deb9c136..7834c6797c89cdb2dfa8800ab8c78ccb7660f7c1 100644 (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);