[erlang-questions] Autogenerating node names
David Sveningsson
ext@REDACTED
Thu Dec 11 15:39:21 CET 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Zvi wrote:
> Hi David,
>
> This is the code I using:
>
>
> start_node(NodeName, Cookie) ->
> _Pid = spawn(os,cmd,[os:find_executable("epmd")++" -daemon"]),
> %% TODO: find something better than sleeep, to wait until epmd is up
> timer:sleep(1000),
> {ok, _} = net_kernel:start([to_atom(NodeName), shortnames]),
> true = erlang:set_cookie(node(), to_atom(Cookie)).
>
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> %% convert any sensible input argument to atom:
> %% i.e, atom, binary, list string, deeplist / IO-list
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> to_atom(S) when is_atom(S) -> S;
> to_atom(S) when is_binary(S) -> list_to_atom(binary_to_list(S));
> to_atom(S) when is_list(S) ->
> try list_to_atom(S) of
> Val -> Val
> catch
> error : _ -> list_to_atom(binary_to_list(erlang:iolist_to_binary(S)))
> end.
>
>
Thanks, but I was hoping to be able to skip the timer part. Does anyone
know when epmd forks? Before or after its initialization?
Let me rephrase that, is epmd ready when "epmd -daemon" returns or must
one wait an unspecified time while it is starting?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAklBJhkACgkQ6pa1H/H5pqVijgCeN+wQOgZHwTjMYyZuWfpuIbe1
noAAnRj4Ct5wnOyx/Wo95MZY6IZnV6oQ
=UBmC
-----END PGP SIGNATURE-----
More information about the erlang-questions
mailing list