]> granicus.if.org Git - ejabberd/commitdiff
Make sure Mnesia dir environment and log file are list, not binary
authorMickael Remond <mremond@process-one.net>
Mon, 6 Apr 2015 09:36:16 +0000 (11:36 +0200)
committerMickael Remond <mremond@process-one.net>
Mon, 6 Apr 2015 09:36:16 +0000 (11:36 +0200)
This is useful for Elixir configuration, as binary is the more natural data type.
Closes #514

src/ejabberd_app.erl
src/ejabberd_config.erl
src/ejabberd_logger.erl

index 4c821cd980baf88f12701233985dcf5421209ad3..cd217ddde688238056f16288dc7cc4459ff4bca3 100644 (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
index 022590bc5fcf476a6696aa8abace4b1afc99443e..5d1df50560fbbd573eef9a65165abe330b2a9bce 100644 (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,
index 59beca16dfbb92a6771223775d5864f460d76607..a00ac9942a33e8cdb37338645da5ab951538c584 100644 (file)
 %% 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 ->