summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/kernel/src/auth.erl42
-rw-r--r--lib/kernel/test/erl_distribution_SUITE.erl35
2 files changed, 58 insertions, 19 deletions
diff --git a/lib/kernel/src/auth.erl b/lib/kernel/src/auth.erl
index 9675d12cd1..796166f89e 100644
--- a/lib/kernel/src/auth.erl
+++ b/lib/kernel/src/auth.erl
@@ -104,32 +104,53 @@ node_cookie(Node, Cookie) ->
-spec get_cookie() -> 'nocookie' | cookie().
get_cookie() ->
- get_cookie(node()).
+ case whereis(auth) of
+ undefined ->
+ nocookie;
+ AuthPid ->
+ gen_server:call(AuthPid, get_our_cookie, infinity)
+ end.
-spec get_cookie(Node :: node()) -> 'nocookie' | cookie().
-get_cookie(Node) when Node =:= nonode@nohost ->
- nocookie;
+get_cookie(Node) when Node =:= node() ->
+ get_cookie();
get_cookie(Node) ->
- gen_server:call(auth, {get_cookie, Node}, infinity).
+ case whereis(auth) of
+ undefined ->
+ nocookie;
+ AuthPid ->
+ gen_server:call(AuthPid, {get_cookie, Node}, infinity)
+ end.
-spec set_cookie(Cookie :: cookie()) -> 'true'.
set_cookie(Cookie) ->
- set_cookie(node(), Cookie).
+ case whereis(auth) of
+ undefined ->
+ erlang:error(distribution_not_started);
+ AuthPid ->
+ gen_server:call(AuthPid, {set_our_cookie, Cookie}, infinity)
+ end.
-spec set_cookie(Node :: node(), Cookie :: cookie()) -> 'true'.
-set_cookie(_Node, _Cookie) when node() =:= nonode@nohost ->
- erlang:error(distribution_not_started);
+set_cookie(Node, Cookie) when Node =:= node() ->
+ set_cookie(Cookie);
set_cookie(Node, Cookie) ->
- gen_server:call(auth, {set_cookie, Node, Cookie}, infinity).
+ case whereis(auth) of
+ undefined ->
+ erlang:error(distribution_not_started);
+ AuthPid ->
+ gen_server:call(AuthPid, {set_cookie, Node, Cookie}, infinity)
+ end.
-spec sync_cookie() -> any().
sync_cookie() ->
gen_server:call(auth, sync_cookie, infinity).
+
-spec print(Node :: node(), Format :: string(), Args :: [_]) -> 'ok'.
print(Node, Format, Args) ->
@@ -154,7 +175,7 @@ init([]) ->
-spec handle_call(calls(), {pid(), term()}, state()) ->
{'reply', 'hello' | 'true' | 'nocookie' | cookie(), state()}.
-handle_call({get_cookie, Node}, {_From,_Tag}, State) when Node =:= node() ->
+handle_call(get_our_cookie, {_From,_Tag}, State) ->
{reply, State#state.our_cookie, State};
handle_call({get_cookie, Node}, {_From,_Tag}, State) ->
case ets:lookup(State#state.other_cookies, Node) of
@@ -163,8 +184,7 @@ handle_call({get_cookie, Node}, {_From,_Tag}, State) ->
[] ->
{reply, State#state.our_cookie, State}
end;
-handle_call({set_cookie, Node, Cookie}, {_From,_Tag}, State)
- when Node =:= node() ->
+handle_call({set_our_cookie, Cookie}, {_From,_Tag}, State) ->
{reply, true, State#state{our_cookie = Cookie}};
%%
diff --git a/lib/kernel/test/erl_distribution_SUITE.erl b/lib/kernel/test/erl_distribution_SUITE.erl
index 873c21a98c..238f4d3365 100644
--- a/lib/kernel/test/erl_distribution_SUITE.erl
+++ b/lib/kernel/test/erl_distribution_SUITE.erl
@@ -66,7 +66,7 @@
epmd_reconnect_do/2,
setopts_do/2,
keep_conn/1, time_ping/1,
- dyn_differing_cookies/2]).
+ ddc_remote_run/2]).
-export([init_per_testcase/2, end_per_testcase/2]).
@@ -2252,14 +2252,25 @@ dyn_differing_cookies(Config) when is_list(Config) ->
%% and cookie configuration of mother node
DynNodeCookieL = BaseName++"_cookieA",
DynNodeCookie = list_to_atom(DynNodeCookieL),
- {_NF, Port} =
+ {_NF1, Port1} =
start_node_unconnected(
"-setcookie "++MotherNodeL++" "++MotherNodeCookieL,
undefined, DynNodeCookie,
?MODULE, run_remote_test,
- [atom_to_list(?FUNCTION_NAME), MotherNodeL] ),
+ ["ddc_remote_run", MotherNodeL, "cmdline", MotherNodeCookieL] ),
+
+ dyn_differing_cookies(MotherNode, MotherNodeCookie, DynNodeCookie, Port1),
+
+ %% Same again, but use erlang:set_cookie/2 to set MotherNodeCookie
+ {_NF2, Port2} =
+ start_node_unconnected(
+ "",
+ undefined, DynNodeCookie,
+ ?MODULE, run_remote_test,
+ ["ddc_remote_run", MotherNodeL, "set_cookie", MotherNodeCookieL] ),
+
+ dyn_differing_cookies(MotherNode, MotherNodeCookie, DynNodeCookie, Port2).
- dyn_differing_cookies(MotherNode, MotherNodeCookie, DynNodeCookie, Port).
dyn_differing_cookies(MotherNode, MotherNodeCookie, DynNodeCookie, Port) ->
receive
@@ -2269,7 +2280,7 @@ dyn_differing_cookies(MotherNode, MotherNodeCookie, DynNodeCookie, Port) ->
DynNodeCookie = rpc:call( DynNode, erlang, get_cookie, [] ),
MotherNodeCookie =
rpc:call( DynNode, erlang, get_cookie, [MotherNode] ),
- {?FUNCTION_NAME, DynNode} !
+ {ddc_remote_run, DynNode} !
{MotherNode, MotherNodeCookie, DynNode},
0 = wait_for_port_exit(Port),
@@ -2284,9 +2295,17 @@ dyn_differing_cookies(MotherNode, MotherNodeCookie, DynNodeCookie, Port) ->
error({unexpected, Other})
end.
-dyn_differing_cookies(MotherNode, _Args) ->
+ddc_remote_run(MotherNode, [SetCookie, MotherNodeCookieL]) ->
nonode@nohost = node(),
[] = nodes(hidden),
+ MotherNodeCookie = list_to_atom(MotherNodeCookieL),
+ case SetCookie of
+ "set_cookie" ->
+ erlang:set_cookie(MotherNode, MotherNodeCookie);
+ "cmdline" ->
+ ok
+ end,
+ MotherNodeCookie = erlang:get_cookie(MotherNode),
true = net_kernel:connect_node( MotherNode ),
[ MotherNode ] = nodes(hidden),
DynNode = node(),
@@ -2296,8 +2315,8 @@ dyn_differing_cookies(MotherNode, _Args) ->
%% Here we get the mother node's default cookie
MotherNodeCookie = rpc:call( MotherNode, erlang, get_cookie, [DynNode] ),
DynNodeCookie = erlang:get_cookie(),
- register( ?FUNCTION_NAME, self() ),
- {?FUNCTION_NAME, MotherNode} !
+ register(ddc_remote_run, self() ),
+ {dyn_differing_cookies, MotherNode} !
{MotherNode, MotherNodeCookie, DynNodeCookie, DynNode},
receive
{ MotherNode, MotherNodeCookie, DynNode } ->