[erlang-questions] initializing library applications without processes
Ulf Wiger
ulf.wiger@REDACTED
Sun Apr 4 10:45:27 CEST 2010
Garrett Smith wrote:
>
> The docs say you can return 'ignore' here as well. I've never tried
> that, but it might give this hack even more panache, assuming it
> doesn't implicitly terminate the process :)
>
> Garrett
Actually, and unfortunately(?), that's exactly what happens.
Here's the relevant code from gen_server:init_it/6:
init_it(Starter, Parent, Name0, Mod, Args, Options) ->
Name = name(Name0),
Debug = debug_options(Name, Options),
case catch Mod:init(Args) of
{ok, State} ->
proc_lib:init_ack(Starter, {ok, self()}),
loop(Parent, Name, State, Mod, infinity, Debug);
...;
ignore ->
unregister_name(Name0),
proc_lib:init_ack(Starter, ignore),
exit(normal);
(supervisor.erl is implemented as a gen_server, and simply
passes on the 'ignore' return value from the Mod:init/1
function.)
Furthermore, in the specific case of application start,
the Mod:start/2 function is required to return a pid:
(from kernel/src/application_master.erl)
start_it_old(Tag, From, Type, ApplData) ->
{M,A} = ApplData#appl_data.mod,
case catch M:start(Type, A) of
{ok, Pid} ->
link(Pid),
From ! {Tag, {ok, self()}},
loop_it(From, Pid, M, []);
{ok, Pid, AppState} ->
link(Pid),
From ! {Tag, {ok, self()}},
loop_it(From, Pid, M, AppState);
{'EXIT', normal} ->
From ! {Tag, {error, {{'EXIT',normal},{M,start,[Type,A]}}}};
{error, Reason} ->
From ! {Tag, {error, {Reason, {M,start,[Type,A]}}}};
Other ->
From ! {Tag, {error,
{bad_return,{{M,start,[Type,A]},Other}}}}
end.
BR,
Ulf W
--
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
http://www.erlang-solutions.com
---------------------------------------------------
---------------------------------------------------
WE'VE CHANGED NAMES!
Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.
www.erlang-solutions.com
More information about the erlang-questions
mailing list