diff options
author | Jean-Sebastien Pedron <jean-sebastien@rabbitmq.com> | 2014-12-03 15:43:57 +0100 |
---|---|---|
committer | Jean-Sebastien Pedron <jean-sebastien@rabbitmq.com> | 2014-12-03 15:43:57 +0100 |
commit | bca1e2ea0903c8ce1c130a08a16f86eff5fb0e44 (patch) | |
tree | d1cec6aff5dba29206f0674d24994c9450d788ed | |
parent | 6205faa415846869ccabe016da6940dd2c966f2e (diff) | |
download | rabbitmq-server-bca1e2ea0903c8ce1c130a08a16f86eff5fb0e44.tar.gz |
Throw an error if at least one plugin's module can't be loadedbug26446
This prevents a plugin from being enabled if it won't be able to
actually run later. A use case for this is a plugin built with Erlang
version N, but executed on Erlang version M, where M isn't capable of
running the bytecode from N. This was the case with Eralng R14B vs.
R15B.
The "rabbitmq-plugins enable <plugin>" command reports the error and the
plugin remains disabled.
A node reports the error too and refuses to start, exactly as if the
plugin was missing.
-rw-r--r-- | src/rabbit_plugins.erl | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl index dfde5289..55f7359b 100644 --- a/src/rabbit_plugins.erl +++ b/src/rabbit_plugins.erl @@ -208,7 +208,27 @@ clean_plugin(Plugin, ExpandDir) -> delete_recursively(rabbit_misc:format("~s/~s", [ExpandDir, Plugin])). prepare_dir_plugin(PluginAppDescPath) -> - code:add_patha(filename:dirname(PluginAppDescPath)). + PluginEbinDir = filename:dirname(PluginAppDescPath), + Plugin = filename:basename(PluginAppDescPath, ".app"), + code:add_patha(PluginEbinDir), + case filelib:wildcard(PluginEbinDir++ "/*.beam") of + [] -> + ok; + [BeamPath | _] -> + Module = list_to_atom(filename:basename(BeamPath, ".beam")), + case code:ensure_loaded(Module) of + {module, _} -> + ok; + {error, badfile} -> + rabbit_log:error("Failed to enable plugin \"~s\": " + "it may have been built with an " + "incompatible (more recent?) " + "version of Erlang~n", [Plugin]), + throw({plugin_built_with_incompatible_erlang, Plugin}); + Error -> + throw({plugin_module_unloadable, Plugin, Error}) + end + end. %%---------------------------------------------------------------------------- |