Supervisor, bridge and error messages

Alessandro Sivieri alessandro.sivieri@REDACTED
Sun May 9 12:39:38 CEST 2010


Hi all,

as a result of a previous discussion, I am now launching processes from a
gen_server with supervisor_bridge, so I can have them under supervision.
The following code is my bridge module:

-module(my_process).
-export([install/1, start/1, init/1, terminate/2]).
install(F) ->
    Key = uuid:uuid(),
    ChildPid = proc_lib:spawn_link(fun() -> F() end),
    Params = {Key, {?MODULE, start, [ChildPid]}, temporary, infinity,
supervisor, [?MODULE]},
    {ok, _BridgePid} = supervisor:start_child(main_sup, Params),
    {Key, ChildPid}.
start([ChildPid]) ->
    supervisor_bridge:start_link(?MODULE, [ChildPid]).
init([ChildPid]) ->
    {ok, ChildPid, ChildPid}.
terminate(_Reason, ChildPid) ->
    exit(ChildPid, kill).

I need to create the non-otp process linked to the supervisor_bridge
externally (in install()), instead of in init(), because I need its pid for
communicating with it, and I have found that I cannot bring any term outside
the init() function; so, this process is created outside and then linked
inside the bridge itself (which should work, I have checked the
supervisor_bridge sources).
But then, when calling install() (with a valid fun as argument), the
following report is created:

** Reason for termination ==
** {{badmatch,
        {error,
            {{'EXIT',
                 {function_clause,
                     [{my_process,start,[<0.68.0>]},
                      {supervisor,do_start_child,2},
                      {supervisor,handle_start_child,2},
                      {supervisor,handle_call,3},
                      {gen_server,handle_msg,5},
                      {proc_lib,init_p_do_apply,3}]}},
             {child,undefined,'17a10803-f064-4718-ae46-4a6d3c88415c',
                 {my_process,start,[<0.68.0>]},
                 temporary,infinity,supervisor,
                 [my_process]}}}},
    [{my_process,install,1},
     {my_peer,handle_call,3},
     {gen_server,handle_msg,5},
     {proc_lib,init_p_do_apply,3}]}

Now, I have no idea from where the EXIT error is produced; I have added a
print line in start(), before start_link, but it seems not to be executed;
what am I doing wrong here?

-- 
Sivieri Alessandro
alessandro.sivieri@REDACTED
http://www.chimera-bellerofonte.eu/
http://www.poul.org/


More information about the erlang-questions mailing list