mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 09:49:18 +02:00
Use auxiliary function to get HOME, use Mnesia directory when not set (#4402)
This commit is contained in:
parent
3196779308
commit
c78e99dd54
7 changed files with 30 additions and 7 deletions
|
@ -44,6 +44,7 @@ start(normal, _Args) ->
|
||||||
ejabberd_logger:start(),
|
ejabberd_logger:start(),
|
||||||
write_pid_file(),
|
write_pid_file(),
|
||||||
start_included_apps(),
|
start_included_apps(),
|
||||||
|
misc:warn_unset_home(),
|
||||||
start_elixir_application(),
|
start_elixir_application(),
|
||||||
setup_if_elixir_conf_used(),
|
setup_if_elixir_conf_used(),
|
||||||
case ejabberd_config:load() of
|
case ejabberd_config:load() of
|
||||||
|
@ -176,6 +177,10 @@ file_queue_init() ->
|
||||||
Err -> throw({?MODULE, Err})
|
Err -> throw({?MODULE, Err})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%%%
|
||||||
|
%%% Elixir
|
||||||
|
%%%
|
||||||
|
|
||||||
-ifdef(ELIXIR_ENABLED).
|
-ifdef(ELIXIR_ENABLED).
|
||||||
is_using_elixir_config() ->
|
is_using_elixir_config() ->
|
||||||
Config = ejabberd_config:path(),
|
Config = ejabberd_config:path(),
|
||||||
|
|
|
@ -503,7 +503,7 @@ get_predefined_keywords(Host) ->
|
||||||
_ ->
|
_ ->
|
||||||
[{<<"HOST">>, Host}]
|
[{<<"HOST">>, Host}]
|
||||||
end,
|
end,
|
||||||
{ok, [[Home]]} = init:get_argument(home),
|
Home = misc:get_home(),
|
||||||
HostList
|
HostList
|
||||||
++ [{<<"HOME">>, list_to_binary(Home)},
|
++ [{<<"HOME">>, list_to_binary(Home)},
|
||||||
{<<"SEMVER">>, ejabberd_option:version()},
|
{<<"SEMVER">>, ejabberd_option:version()},
|
||||||
|
|
|
@ -222,7 +222,7 @@ setup_provisional_udsocket_dir(DefinitivePath) ->
|
||||||
|
|
||||||
get_provisional_udsocket_path(Path) ->
|
get_provisional_udsocket_path(Path) ->
|
||||||
PathBase64 = misc:term_to_base64(Path),
|
PathBase64 = misc:term_to_base64(Path),
|
||||||
PathBuild = filename:join(os:getenv("HOME"), PathBase64),
|
PathBuild = filename:join(misc:get_home(), PathBase64),
|
||||||
%% Shorthen the path, a long path produces a crash when opening the socket.
|
%% Shorthen the path, a long path produces a crash when opening the socket.
|
||||||
binary:part(PathBuild, {0, erlang:min(107, byte_size(PathBuild))}).
|
binary:part(PathBuild, {0, erlang:min(107, byte_size(PathBuild))}).
|
||||||
|
|
||||||
|
|
|
@ -1376,7 +1376,7 @@ write_file_if_new(File, Payload) ->
|
||||||
|
|
||||||
tmp_dir() ->
|
tmp_dir() ->
|
||||||
case os:type() of
|
case os:type() of
|
||||||
{win32, _} -> filename:join([os:getenv("HOME"), "conf"]);
|
{win32, _} -> filename:join([misc:get_home(), "conf"]);
|
||||||
_ -> filename:join(["/tmp", "ejabberd"])
|
_ -> filename:join(["/tmp", "ejabberd"])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -371,8 +371,6 @@ geturl(Url) ->
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
getenv(Env) ->
|
|
||||||
getenv(Env, "").
|
|
||||||
getenv(Env, Default) ->
|
getenv(Env, Default) ->
|
||||||
case os:getenv(Env) of
|
case os:getenv(Env) of
|
||||||
false -> Default;
|
false -> Default;
|
||||||
|
@ -453,7 +451,7 @@ delete_path(Path, Package) ->
|
||||||
delete_path(filename:join(filename:dirname(Path), Package)).
|
delete_path(filename:join(filename:dirname(Path), Package)).
|
||||||
|
|
||||||
modules_dir() ->
|
modules_dir() ->
|
||||||
DefaultDir = filename:join(getenv("HOME"), ".ejabberd-modules"),
|
DefaultDir = filename:join(misc:get_home(), ".ejabberd-modules"),
|
||||||
getenv("CONTRIB_MODULES_PATH", DefaultDir).
|
getenv("CONTRIB_MODULES_PATH", DefaultDir).
|
||||||
|
|
||||||
sources_dir() ->
|
sources_dir() ->
|
||||||
|
|
20
src/misc.erl
20
src/misc.erl
|
@ -36,6 +36,7 @@
|
||||||
l2i/1, i2l/1, i2l/2, expr_to_term/1, term_to_expr/1,
|
l2i/1, i2l/1, i2l/2, expr_to_term/1, term_to_expr/1,
|
||||||
now_to_usec/1, usec_to_now/1, encode_pid/1, decode_pid/2,
|
now_to_usec/1, usec_to_now/1, encode_pid/1, decode_pid/2,
|
||||||
compile_exprs/2, join_atoms/2, try_read_file/1, get_descr/2,
|
compile_exprs/2, join_atoms/2, try_read_file/1, get_descr/2,
|
||||||
|
get_home/0, warn_unset_home/0,
|
||||||
css_dir/0, img_dir/0, js_dir/0, msgs_dir/0, sql_dir/0, lua_dir/0,
|
css_dir/0, img_dir/0, js_dir/0, msgs_dir/0, sql_dir/0, lua_dir/0,
|
||||||
read_css/1, read_img/1, read_js/1, read_lua/1,
|
read_css/1, read_img/1, read_js/1, read_lua/1,
|
||||||
intersection/2, format_val/1, cancel_timer/1, unique_timestamp/0,
|
intersection/2, format_val/1, cancel_timer/1, unique_timestamp/0,
|
||||||
|
@ -470,6 +471,25 @@ get_descr(Lang, Text) ->
|
||||||
Copyright = ejabberd_config:get_copyright(),
|
Copyright = ejabberd_config:get_copyright(),
|
||||||
<<Desc/binary, $\n, Copyright/binary>>.
|
<<Desc/binary, $\n, Copyright/binary>>.
|
||||||
|
|
||||||
|
-spec get_home() -> string().
|
||||||
|
get_home() ->
|
||||||
|
case init:get_argument(home) of
|
||||||
|
{ok, [[Home]]} ->
|
||||||
|
Home;
|
||||||
|
error ->
|
||||||
|
mnesia:system_info(directory)
|
||||||
|
end.
|
||||||
|
|
||||||
|
warn_unset_home() ->
|
||||||
|
case init:get_argument(home) of
|
||||||
|
{ok, [[_Home]]} ->
|
||||||
|
ok;
|
||||||
|
error ->
|
||||||
|
?INFO_MSG("The 'HOME' environment variable is not set, "
|
||||||
|
"ejabberd will use as HOME the Mnesia directory: ~s.",
|
||||||
|
[mnesia:system_info(directory)])
|
||||||
|
end.
|
||||||
|
|
||||||
-spec intersection(list(), list()) -> list().
|
-spec intersection(list(), list()) -> list().
|
||||||
intersection(L1, L2) ->
|
intersection(L1, L2) ->
|
||||||
lists:filter(
|
lists:filter(
|
||||||
|
|
|
@ -717,7 +717,7 @@ get_proc_name(ServerHost, ModuleName, PutURL) ->
|
||||||
|
|
||||||
-spec expand_home(binary()) -> binary().
|
-spec expand_home(binary()) -> binary().
|
||||||
expand_home(Input) ->
|
expand_home(Input) ->
|
||||||
{ok, [[Home]]} = init:get_argument(home),
|
Home = misc:get_home(),
|
||||||
misc:expand_keyword(<<"@HOME@">>, Input, Home).
|
misc:expand_keyword(<<"@HOME@">>, Input, Home).
|
||||||
|
|
||||||
-spec expand_host(binary(), binary()) -> binary().
|
-spec expand_host(binary(), binary()) -> binary().
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue