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 | b865b398460c8f7f28d66172647126711c07d257 (patch) | |
| tree | d1cec6aff5dba29206f0674d24994c9450d788ed | |
| parent | dc77cc2e7ed62a70518ac416a90174aacdce07d8 (diff) | |
| download | rabbitmq-server-git-b865b398460c8f7f28d66172647126711c07d257.tar.gz | |
Throw an error if at least one plugin's module can't be loaded
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 dfde5289d1..55f7359b71 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. %%---------------------------------------------------------------------------- |
