25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Make sure Mnesia dir environment and log file are list, not binary

This is useful for Elixir configuration, as binary is the more natural data type.
Closes #514
This commit is contained in:
Mickael Remond 2015-04-06 11:36:16 +02:00
parent ea8db9967f
commit 47537aa901
3 changed files with 22 additions and 2 deletions

View File

@ -110,6 +110,7 @@ loop() ->
end.
db_init() ->
ejabberd_config:env_binary_to_list(mnesia, dir),
MyNode = node(),
DbNodes = mnesia:system_info(db_nodes),
case lists:member(MyNode, DbNodes) of

View File

@ -35,7 +35,8 @@
get_version/0, get_myhosts/0, get_mylang/0,
prepare_opt_val/4, convert_table_to_binary/5,
transform_options/1, collect_options/1,
convert_to_yaml/1, convert_to_yaml/2]).
convert_to_yaml/1, convert_to_yaml/2,
env_binary_to_list/2]).
-include("ejabberd.hrl").
-include("logger.hrl").
@ -167,6 +168,22 @@ convert_to_yaml(File, Output) ->
file:write_file(FileName, Data)
end.
%% Some Erlang apps expects env parameters to be list and not binary.
%% For example, Mnesia is not able to start if mnesia dir is passed as a binary.
%% However, binary is most common on Elixir, so it is easy to make a setup mistake.
-spec env_binary_to_list(atom(), atom()) -> {ok, any()}|undefined.
env_binary_to_list(Application, Parameter) ->
%% Application need to be loaded to allow setting parameters
application:load(Application),
case application:get_env(Application, Parameter) of
{ok, Val} when is_binary(Val) ->
BVal = binary_to_list(Val),
application:set_env(Application, Parameter, BVal),
{ok, BVal};
Other ->
Other
end.
%% @doc Read an ejabberd configuration file and return the terms.
%% Input is an absolute or relative path to an ejabberd config file.
%% Returns a list of plain terms,

View File

@ -46,8 +46,10 @@
%% If not defined it checks the environment variable EJABBERD_LOG_PATH.
%% And if that one is neither defined, returns the default value:
%% "ejabberd.log" in current directory.
%% Note: If the directory where to place the ejabberd log file to not exist,
%% it is not created and no log file will be generated.
get_log_path() ->
case application:get_env(ejabberd, log_path) of
case ejabberd_config:env_binary_to_list(ejabberd, log_path) of
{ok, Path} ->
Path;
undefined ->