Skip to content

Commit 74dfa4d

Browse files
author
Simon MacMullen
committed
Merge bug24579
2 parents e58525e + fdb6e3b commit 74dfa4d

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

docs/rabbitmqctl.1.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,22 @@
13151315
</para>
13161316
</listitem>
13171317
</varlistentry>
1318+
1319+
<varlistentry>
1320+
<term><cmdsynopsis><command>eval</command> <arg choice="req"><replaceable>expr</replaceable></arg></cmdsynopsis></term>
1321+
<listitem>
1322+
<para>
1323+
Evaluate an arbitrary Erlang expression.
1324+
</para>
1325+
<para role="example-prefix">
1326+
For example:
1327+
</para>
1328+
<screen role="example">rabbitmqctl eval 'node().'</screen>
1329+
<para role="example">
1330+
This command returns the name of the node to which rabbitmqctl has connected.
1331+
</para>
1332+
</listitem>
1333+
</varlistentry>
13181334
</variablelist>
13191335
</refsect2>
13201336

src/mirrored_supervisor_tests.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ test_no_migration_on_shutdown() ->
158158
try
159159
call(worker, ping),
160160
exit(worker_should_not_have_migrated)
161-
catch exit:{timeout_waiting_for_server, _} ->
161+
catch exit:{timeout_waiting_for_server, _, _} ->
162162
ok
163163
end
164164
end, [evil, good]).
@@ -245,10 +245,10 @@ inc_group() ->
245245
get_group(Group) ->
246246
{Group, get(counter)}.
247247

248-
call(Id, Msg) -> call(Id, Msg, 100, 10).
248+
call(Id, Msg) -> call(Id, Msg, 1000, 100).
249249

250250
call(Id, Msg, 0, _Decr) ->
251-
exit({timeout_waiting_for_server, {Id, Msg}});
251+
exit({timeout_waiting_for_server, {Id, Msg}, erlang:get_stacktrace()});
252252

253253
call(Id, Msg, MaxDelay, Decr) ->
254254
try

src/rabbit_control.erl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ start() ->
9898
{error, Reason} ->
9999
print_error("~p", [Reason]),
100100
rabbit_misc:quit(2);
101+
{error_string, Reason} ->
102+
print_error("~s", [Reason]),
103+
rabbit_misc:quit(2);
101104
{badrpc, {'EXIT', Reason}} ->
102105
print_error("~p", [Reason]),
103106
rabbit_misc:quit(2);
@@ -368,7 +371,23 @@ action(report, Node, _Args, _Opts, Inform) ->
368371
[print_report(Node, Q) || Q <- ?GLOBAL_QUERIES],
369372
[print_report(Node, Q, [V]) || Q <- ?VHOST_QUERIES, V <- VHosts],
370373
io:format("End of server status report~n"),
371-
ok.
374+
ok;
375+
376+
action(eval, Node, [Expr], _Opts, _Inform) ->
377+
case erl_scan:string(Expr) of
378+
{ok, Scanned, _} ->
379+
case erl_parse:parse_exprs(Scanned) of
380+
{ok, Parsed} ->
381+
{value, Value, _} = unsafe_rpc(
382+
Node, erl_eval, exprs, [Parsed, []]),
383+
io:format("~p~n", [Value]),
384+
ok;
385+
{error, E} ->
386+
{error_string, format_parse_error(E)}
387+
end;
388+
{error, E, _} ->
389+
{error_string, format_parse_error(E)}
390+
end.
372391

373392
%%----------------------------------------------------------------------------
374393

@@ -443,6 +462,9 @@ system(Cmd) ->
443462
escape_quotes(Cmd) ->
444463
lists:flatten(lists:map(fun ($') -> "'\\''"; (Ch) -> Ch end, Cmd)).
445464

465+
format_parse_error({_Line, Mod, Err}) ->
466+
lists:flatten(Mod:format_error(Err)).
467+
446468
%%----------------------------------------------------------------------------
447469

448470
default_if_empty(List, Default) when is_list(List) ->

src/rabbit_guid.erl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,15 @@ guid() ->
8989
erlang:md5(term_to_binary(G)).
9090

9191
%% generate a readable string representation of a GUID.
92+
%%
93+
%% employs base64url encoding, which is safer in more contexts than
94+
%% plain base64.
9295
string_guid(Prefix) ->
93-
Prefix ++ "-" ++ base64:encode_to_string(guid()).
96+
Prefix ++ "-" ++ lists:foldl(fun ($\+, Acc) -> [$\- | Acc];
97+
($\/, Acc) -> [$\_ | Acc];
98+
($\=, Acc) -> Acc;
99+
(Chr, Acc) -> [Chr | Acc]
100+
end, [], base64:encode_to_string(guid())).
94101

95102
binstring_guid(Prefix) ->
96103
list_to_binary(string_guid(Prefix)).

0 commit comments

Comments
 (0)