From 94b74c0cbe22e9eebaaa9a9eb108f2205ba5b836 Mon Sep 17 00:00:00 2001 From: Evgeny Khramtsov Date: Thu, 7 Nov 2019 10:47:11 +0300 Subject: [PATCH] Fix loading of third-party modules at startup Fixes #3019 --- src/ejabberd_config.erl | 18 +++++++++--------- src/ext_mod.erl | 10 +++++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/ejabberd_config.erl b/src/ejabberd_config.erl index dac5249ca..d78d23356 100644 --- a/src/ejabberd_config.erl +++ b/src/ejabberd_config.erl @@ -283,6 +283,14 @@ beams(local) -> Mods; beams(external) -> ExtMods = [Name || {Name, _Details} <- ext_mod:installed()], + lists:foreach( + fun(ExtMod) -> + ExtModPath = ext_mod:module_ebin_dir(ExtMod), + case lists:member(ExtModPath, code:get_path()) of + true -> ok; + false -> code:add_patha(ExtModPath) + end + end, ExtMods), case application:get_env(ejabberd, external_beams) of {ok, Path} -> case lists:member(Path, code:get_path()) of @@ -468,14 +476,6 @@ validators(Mod, Disallowed) -> end end, proplists:get_keys(Mod:options()))). --spec get_modules_configs() -> [binary()]. -get_modules_configs() -> - Fs = [{filename:rootname(filename:basename(F)), F} - || F <- filelib:wildcard(ext_mod:config_dir() ++ "/*.{yml,yaml}") - ++ filelib:wildcard(ext_mod:modules_dir() ++ "/*/conf/*.{yml,yaml}")], - [unicode:characters_to_binary(proplists:get_value(F, Fs)) - || F <- proplists:get_keys(Fs)]. - read_file(File) -> read_file(File, [replace_macros, include_files, include_modules_configs]). @@ -484,7 +484,7 @@ read_file(File, Opts) -> Ret = case filename:extension(File) of Ex when Ex == <<".yml">> orelse Ex == <<".yaml">> -> Files = case proplists:get_bool(include_modules_configs, Opts2) of - true -> get_modules_configs(); + true -> ext_mod:modules_configs(); false -> [] end, lists:foreach( diff --git a/src/ext_mod.erl b/src/ext_mod.erl index e193698ed..19a489fb0 100644 --- a/src/ext_mod.erl +++ b/src/ext_mod.erl @@ -34,7 +34,7 @@ install/1, uninstall/1, upgrade/0, upgrade/1, add_paths/0, add_sources/1, add_sources/2, del_sources/1, modules_dir/0, config_dir/0, get_commands_spec/0]). - +-export([modules_configs/0, module_ebin_dir/1]). -export([compile_erlang_file/2, compile_elixir_file/2]). %% gen_server callbacks @@ -426,6 +426,14 @@ config_dir() -> DefaultDir = filename:join(modules_dir(), "conf"), getenv("CONTRIB_MODULES_CONF_DIR", DefaultDir). +-spec modules_configs() -> [binary()]. +modules_configs() -> + Fs = [{filename:rootname(filename:basename(F)), F} + || F <- filelib:wildcard(config_dir() ++ "/*.{yml,yaml}") + ++ filelib:wildcard(modules_dir() ++ "/*/conf/*.{yml,yaml}")], + [unicode:characters_to_binary(proplists:get_value(F, Fs)) + || F <- proplists:get_keys(Fs)]. + module_lib_dir(Package) -> filename:join(modules_dir(), Package).