예제 #1
0
파일: plugin.c 프로젝트: Cytrian/syslog-ng
Plugin *
plugin_find(GlobalConfig *cfg, gint plugin_type, const gchar *plugin_name)
{
  Plugin *p;
  PluginCandidate *candidate;

  /* try registered plugins first */
  p = plugin_find_in_list(cfg, cfg->plugins, plugin_type, plugin_name);
  if (p)
    return p;

  candidate = (PluginCandidate *) plugin_find_in_list(cfg, cfg->candidate_plugins, plugin_type, plugin_name);
  if (!candidate)
    return NULL;

  /* try to autoload the module */
  plugin_load_module(candidate->module_name, cfg, NULL);

  /* by this time it should've registered */
  p = plugin_find_in_list(cfg, cfg->plugins, plugin_type, plugin_name);
  if (p)
    {
      return p;
    }
  else
    {
      msg_error("This module claims to support a plugin, which it didn't register after loading",
                evt_tag_str("module", candidate->module_name),
                evt_tag_str("context", cfg_lexer_lookup_context_name_by_type(plugin_type)),
                evt_tag_str("name", plugin_name));
    }
  return NULL;
}
예제 #2
0
파일: plugin.c 프로젝트: Cytrian/syslog-ng
void
plugin_register(GlobalConfig *cfg, Plugin *p, gint number)
{
  gint i;

  for (i = 0; i < number; i++)
    {
      if (plugin_find_in_list(cfg, cfg->plugins, p[i].type, p[i].name))
        {
          msg_debug("Attempted to register the same plugin multiple times, ignoring",
                    evt_tag_str("context", cfg_lexer_lookup_context_name_by_type(p[i].type)),
                    evt_tag_str("name", p[i].name));
          continue;
        }
      cfg->plugins = g_list_prepend(cfg->plugins, &p[i]);
    }
}
예제 #3
0
파일: plugin.c 프로젝트: pgit/syslog-ng-3.4
void
plugin_load_candidate_modules(GlobalConfig *cfg)
{
  GModule *mod;
  gchar **mod_paths;
  gint i, j;

  mod_paths = g_strsplit(module_path, ":", 0);
  for (i = 0; mod_paths[i]; i++)
    {
      GDir *dir;
      const gchar *fname;

      dir = g_dir_open(mod_paths[i], 0, NULL);
      if (!dir)
        continue;
      while ((fname = g_dir_read_name(dir)))
        {
          if (g_str_has_suffix(fname, G_MODULE_SUFFIX))
            {
              gchar *module_name;
              ModuleInfo *module_info;
              gboolean success;

              if (g_str_has_prefix(fname, "lib"))
                fname += 3;
              module_name = g_strndup(fname, (gint) (strlen(fname) - strlen(G_MODULE_SUFFIX) - 1));

              mod = plugin_dlopen_module(module_name, module_path);
              if (mod)
                success = g_module_symbol(mod, "module_info", (gpointer *) &module_info);
              else
                success = FALSE;

              if (success && module_info)
                {
                  for (j = 0; j < module_info->plugins_len; j++)
                    {
                      Plugin *plugin = &module_info->plugins[j];
                      PluginCandidate *candidate_plugin;

                      candidate_plugin = (PluginCandidate *) plugin_find_in_list(cfg, cfg->candidate_plugins, plugin->type, plugin->name);
                      if (candidate_plugin)
                        {
                          if (candidate_plugin->preference < module_info->preference)
                            {
                              plugin_candidate_set_module_name(candidate_plugin, module_info->canonical_name);
                              plugin_candidate_set_preference(candidate_plugin, module_info->preference);
                            }
                        }
                      else
                        {
                          cfg->candidate_plugins = g_list_prepend(cfg->candidate_plugins, plugin_candidate_new(plugin->type, plugin->name, module_info->canonical_name, module_info->preference));
                        }
                    }
                }
              g_free(module_name);
              if (mod)
                g_module_close(mod);
              else
                mod = NULL;
            }
        }
      g_dir_close(dir);
    }
  g_strfreev(mod_paths);
}