terminate imc/imv that couldn't be initialized properly
[strongswan.git] / src / libcharon / plugins / tnc_imc / tnc_imc_plugin.c
index 683efc1..bc13b87 100644 (file)
@@ -130,16 +130,29 @@ static bool load_imcs(char *filename)
                }
                if (!charon->imcs->add(charon->imcs, imc))
                {
+                       if (imc->terminate &&
+                               imc->terminate(imc->get_id(imc)) != TNC_RESULT_SUCCESS)
+                       {
+                               DBG1(DBG_TNC, "IMC \"%s\" not terminated successfully",
+                                                          imc->get_name(imc));
+                       }
                        imc->destroy(imc);
                        return FALSE;
                }
-               DBG1(DBG_TNC, "IMC \"%s\" loaded from '%s'", name, path);
+               DBG1(DBG_TNC, "IMC %u \"%s\" loaded from '%s'", imc->get_id(imc),
+                                                                                                               name, path);
        }
        munmap(addr, sb.st_size);
        close(fd);
        return TRUE;
 }
 
+METHOD(plugin_t, get_name, char*,
+       tnc_imc_plugin_t *this)
+{
+       return "tnc-imc";
+}
+
 METHOD(plugin_t, destroy, void,
        tnc_imc_plugin_t *this)
 {
@@ -152,27 +165,27 @@ METHOD(plugin_t, destroy, void,
  */
 plugin_t *tnc_imc_plugin_create()
 {
-       char *tnc_config, *pref_lang;
+       char *tnc_config;
        tnc_imc_plugin_t *this;
 
        INIT(this,
                .plugin = {
+                       .get_name = _get_name,
+                               .reload = (void*)return_false,
                        .destroy = _destroy,
                },
        );
 
-       pref_lang = lib->settings->get_str(lib->settings,
-                                       "charon.plugins.tnc-imc.preferred_language", "en");
-       tnc_config = lib->settings->get_str(lib->settings,
-                                       "charon.plugins.tnc-imc.tnc_config", "/etc/tnc_config");
-
        /* Create IMC manager */
        charon->imcs = tnc_imc_manager_create();
 
        /* Load IMCs and abort if not all instances initalize successfully */
+       tnc_config = lib->settings->get_str(lib->settings,
+                                       "charon.plugins.tnc-imc.tnc_config", "/etc/tnc_config");
        if (!load_imcs(tnc_config))
        {
                charon->imcs->destroy(charon->imcs);
+               charon->imcs = NULL;
                free(this);
                return NULL;
        }