aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded/src/erl_prim_loader.erl
diff options
context:
space:
mode:
Diffstat (limited to 'erts/preloaded/src/erl_prim_loader.erl')
-rw-r--r--erts/preloaded/src/erl_prim_loader.erl76
1 files changed, 42 insertions, 34 deletions
diff --git a/erts/preloaded/src/erl_prim_loader.erl b/erts/preloaded/src/erl_prim_loader.erl
index c0785083de..a13292d5ab 100644
--- a/erts/preloaded/src/erl_prim_loader.erl
+++ b/erts/preloaded/src/erl_prim_loader.erl
@@ -51,22 +51,25 @@
%% Used by escript and code
-export([set_primary_archive/3, release_archives/0]).
-%% Internal function. Exported to avoid dialyzer warnings
--export([concat/1]).
-
-include_lib("kernel/include/file.hrl").
-type host() :: atom().
+-record(prim_state, {debug :: boolean(),
+ cache,
+ primary_archive}).
+-type prim_state() :: #prim_state{}.
+
-record(state,
- {loader :: 'efile' | 'inet',
- hosts = [] :: [host()], % hosts list (to boot from)
+ {loader :: 'efile' | 'inet',
+ hosts = [] :: [host()], % hosts list (to boot from)
id, % not used any more?
- data, % data port etc
- timeout, % idle timeout
- n_timeouts, % Number of timeouts before archives are released
- multi_get = false :: boolean(),
- prim_state}). % state for efile code loader
+ data :: 'noport' | port(), % data port etc
+ timeout :: timeout(), % idle timeout
+ %% Number of timeouts before archives are released
+ n_timeouts :: non_neg_integer(),
+ multi_get = false :: boolean(),
+ prim_state :: prim_state()}). % state for efile code loader
-define(IDLE_TIMEOUT, 60000). %% tear inet connection after 1 minutes
-define(N_TIMEOUTS, 6). %% release efile archive after 6 minutes
@@ -89,8 +92,6 @@
end
end()).
--record(prim_state, {debug, cache, primary_archive}).
-
debug(#prim_state{debug = Deb}, Term) ->
case Deb of
false -> ok;
@@ -124,7 +125,7 @@ start(Id, Pgm0, Hosts) ->
start_it("ose_inet"=Cmd, Id, Pid, Hosts) ->
%% Setup reserved port for ose_inet driver (only OSE)
- case catch erlang:open_port({spawn,Cmd},[binary]) of
+ case catch erlang:open_port({spawn,Cmd}, [binary]) of
{'EXIT',Why} ->
?dbg(ose_inet_port_open_fail, Why),
Why;
@@ -317,7 +318,7 @@ loop(State, Parent, Paths) ->
{Res,State1} = handle_get_cwd(State, Args),
{Res,State1,Paths};
{set_primary_archive,File,Bin,FileInfo} ->
- {Res,State1} = handle_set_primary_archive(State, File, Bin,FileInfo),
+ {Res,State1} = handle_set_primary_archive(State, File, Bin, FileInfo),
{Res,State1,Paths};
release_archives ->
{Res,State1} = handle_release_archives(State),
@@ -326,7 +327,7 @@ loop(State, Parent, Paths) ->
{ignore,State,Paths}
end,
if Resp =:= ignore -> ok;
- true -> Pid ! {self(),Resp}
+ true -> Pid ! {self(),Resp}, ok
end,
if
is_record(State2, state) ->
@@ -335,7 +336,7 @@ loop(State, Parent, Paths) ->
exit({bad_state, Req, State2})
end;
{'EXIT',Parent,W} ->
- handle_stop(State),
+ _State1 = handle_stop(State),
exit(W);
{'EXIT',P,W} ->
State1 = handle_exit(State, P, W),
@@ -605,7 +606,6 @@ find_collect(U,Retry,AL,Delay,Acc) ->
_Garbage ->
?dbg(collect_garbage, _Garbage),
find_collect(U, Retry, AL, Delay, Acc)
-
after Delay ->
?dbg(collected, Acc),
case keymember(0, 1, Acc) of %% got high priority server?
@@ -619,7 +619,7 @@ sleep(Time) ->
receive after Time -> ok end.
inet_exit_port(State, Port, _Reason) when State#state.data =:= Port ->
- State#state { data = noport, timeout = infinity };
+ State#state{data = noport, timeout = infinity};
inet_exit_port(State, _, _) ->
State.
@@ -629,7 +629,7 @@ inet_timeout_handler(State, _Parent) ->
if is_port(Tcp) -> ll_close(Tcp);
true -> ok
end,
- State#state { timeout = infinity, data = noport }.
+ State#state{timeout = infinity, data = noport}.
%% -> {{ok,BinFile,Tag},State} | {{error,Reason},State}
inet_get_file_from_port(State, File, Paths) ->
@@ -659,9 +659,9 @@ inet_get_file_from_port1(_File, [], State) ->
inet_send_and_rcv(Msg, Tag, State) when State#state.data =:= noport ->
{ok,Tcp} = find_master(State#state.hosts), %% reconnect
- inet_send_and_rcv(Msg, Tag, State#state { data = Tcp,
- timeout = ?IDLE_TIMEOUT });
-inet_send_and_rcv(Msg, Tag, #state{data=Tcp,timeout=Timeout}=State) ->
+ inet_send_and_rcv(Msg, Tag, State#state{data = Tcp,
+ timeout = ?IDLE_TIMEOUT});
+inet_send_and_rcv(Msg, Tag, #state{data = Tcp, timeout = Timeout} = State) ->
prim_inet:send(Tcp, term_to_binary(Msg)),
receive
{tcp,Tcp,BinMsg} ->
@@ -679,13 +679,13 @@ inet_send_and_rcv(Msg, Tag, #state{data=Tcp,timeout=Timeout}=State) ->
end;
{tcp_closed,Tcp} ->
%% Ok we must reconnect
- inet_send_and_rcv(Msg, Tag, State#state { data = noport });
+ inet_send_and_rcv(Msg, Tag, State#state{data = noport});
{tcp_error,Tcp,_Reason} ->
%% Ok we must reconnect
inet_send_and_rcv(Msg, Tag, inet_stop_port(State));
{'EXIT', Tcp, _} ->
%% Ok we must reconnect
- inet_send_and_rcv(Msg, Tag, State#state { data = noport })
+ inet_send_and_rcv(Msg, Tag, State#state{data = noport})
after Timeout ->
%% Ok we must reconnect
inet_send_and_rcv(Msg, Tag, inet_stop_port(State))
@@ -772,6 +772,7 @@ port_error(S, Error) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec prim_init() -> prim_state().
prim_init() ->
Deb =
case init:get_argument(loader_debug) of
@@ -779,10 +780,10 @@ prim_init() ->
error -> false
end,
cache_new(#prim_state{debug = Deb}).
-
+
prim_release_archives(PS) ->
debug(PS, release_archives),
- {Res, PS2}= prim_do_release_archives(PS, get(), []),
+ {Res, PS2} = prim_do_release_archives(PS, get(), []),
debug(PS2, {return, Res}),
{Res, PS2}.
@@ -822,8 +823,8 @@ prim_set_primary_archive(PS, undefined, undefined, undefined) ->
debug(PS2, {return, Res}),
{Res, PS2}
end;
-prim_set_primary_archive(PS, ArchiveFile, ArchiveBin, FileInfo)
- when is_list(ArchiveFile), is_binary(ArchiveBin), is_record(FileInfo, file_info) ->
+prim_set_primary_archive(PS, ArchiveFile, ArchiveBin, #file_info{} = FileInfo)
+ when is_list(ArchiveFile), is_binary(ArchiveBin) ->
%% Try the archive file
debug(PS, {set_primary_archive, ArchiveFile, byte_size(ArchiveBin)}),
{Res3, PS3} =
@@ -861,6 +862,7 @@ prim_set_primary_archive(PS, ArchiveFile, ArchiveBin, FileInfo)
debug(PS3, {return, Res3}),
{Res3, PS3}.
+-spec prim_get_file(prim_state(), file:filename()) -> {_, prim_state()}.
prim_get_file(PS, File) ->
debug(PS, {get_file, File}),
{Res2, PS2} =
@@ -885,7 +887,9 @@ prim_get_file(PS, File) ->
debug(PS, {return, Res2}),
{Res2, PS2}.
-%% -> {{ok,List},State} | {{error,Reason},State}
+-spec prim_list_dir(prim_state(), file:filename()) ->
+ {{'ok', [file:filename()]}, prim_state()}
+ | {{'error', term()}, prim_state()}.
prim_list_dir(PS, Dir) ->
debug(PS, {list_dir, Dir}),
{Res2, PS3} =
@@ -936,7 +940,9 @@ prim_list_dir(PS, Dir) ->
debug(PS, {return, Res2}),
{Res2, PS3}.
-%% -> {{ok,Info},State} | {{error,Reason},State}
+-spec prim_read_file_info(prim_state(), file:filename()) ->
+ {{'ok', #file_info{}}, prim_state()}
+ | {{'error', term()}, prim_state()}.
prim_read_file_info(PS, File) ->
debug(PS, {read_file_info, File}),
{Res2, PS2} =
@@ -976,6 +982,8 @@ prim_read_file_info(PS, File) ->
debug(PS2, {return, Res2}),
{Res2, PS2}.
+-spec prim_get_cwd(prim_state(), [file:filename()]) ->
+ {{'error', term()} | {'ok', _}, prim_state()}.
prim_get_cwd(PS, []) ->
debug(PS, {get_cwd, []}),
Res = prim_file:get_cwd(),
@@ -1029,7 +1037,7 @@ apply_archive(PS, Fun, Acc, Archive) ->
{Acc2, PS};
Error ->
debug(PS, {cache, {clear, Error}}),
- clear_cache(Archive, Cache),
+ ok = clear_cache(Archive, Cache),
debug(PS, {cache, Error}),
erase(Archive),
%% put(Archive, {Error, FI}),
@@ -1041,7 +1049,7 @@ apply_archive(PS, Fun, Acc, Archive) ->
end;
Error ->
debug(PS, {cache, {clear, Error}}),
- clear_cache(Archive, Cache),
+ ok = clear_cache(Archive, Cache),
apply_archive(PS, Fun, Acc, Archive)
end
end.
@@ -1143,8 +1151,8 @@ send_all(U, [IP | AL], Cmd) ->
send_all(U, AL, Cmd);
send_all(_U, [], _) -> ok.
-concat([A|T]) when is_atom(A) -> %Atom
- atom_to_list(A) ++ concat(T);
+%%concat([A|T]) when is_atom(A) -> %Atom
+%% atom_to_list(A) ++ concat(T);
concat([C|T]) when C >= 0, C =< 255 ->
[C|concat(T)];
concat([S|T]) -> %String