emqttd:seed_now/0 to replace random:seed(now())
This commit is contained in:
parent
3af624a6c3
commit
22a282e39e
|
@ -29,7 +29,7 @@
|
|||
-export([start/0, env/1, env/2,
|
||||
start_listeners/0, stop_listeners/0,
|
||||
load_all_mods/0, is_mod_enabled/1,
|
||||
is_running/1]).
|
||||
is_running/1, seed_now/0]).
|
||||
|
||||
%% Utility functions.
|
||||
-export([reg_name/2]).
|
||||
|
@ -139,3 +139,12 @@ is_running(Node) ->
|
|||
reg_name(M, Id) when is_atom(M), is_integer(Id) ->
|
||||
list_to_atom(lists:concat([M, "_", Id])).
|
||||
|
||||
seed_now() ->
|
||||
case erlang:function_exported(erlang, timestamp, 0) of
|
||||
true -> %% R18
|
||||
random:seed(erlang:timestamp());
|
||||
false ->
|
||||
%% compress 'now()' warning...
|
||||
random:seed(os:timestamp())
|
||||
end.
|
||||
|
||||
|
|
|
@ -142,8 +142,7 @@ md5_hash(SaltBin, Password) ->
|
|||
erlang:md5(<<SaltBin/binary, Password/binary>>).
|
||||
|
||||
salt() ->
|
||||
{A1,A2,A3} = now(),
|
||||
random:seed(A1, A2, A3),
|
||||
emqttd:seed_now(),
|
||||
Salt = random:uniform(16#ffffffff),
|
||||
<<Salt:32>>.
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ stop_tick(TRef) ->
|
|||
%%%=============================================================================
|
||||
|
||||
init([]) ->
|
||||
random:seed(os:timestamp()),
|
||||
emqttd:seed_now(),
|
||||
ets:new(?BROKER_TAB, [set, public, named_table]),
|
||||
% Create $SYS Topics
|
||||
emqttd_pubsub:create(topic, <<"$SYS/brokers">>),
|
||||
|
|
|
@ -283,7 +283,7 @@ key(counter, Metric) ->
|
|||
%%%=============================================================================
|
||||
|
||||
init([]) ->
|
||||
random:seed(os:timestamp()),
|
||||
emqttd:seed_now(),
|
||||
Metrics = ?SYSTOP_BYTES ++ ?SYSTOP_PACKETS ++ ?SYSTOP_MESSAGES,
|
||||
% Create metrics table
|
||||
ets:new(?METRIC_TAB, [set, public, named_table, {write_concurrency, true}]),
|
||||
|
|
|
@ -143,7 +143,7 @@ setstats(Stat, MaxStat, Val) ->
|
|||
%%%=============================================================================
|
||||
|
||||
init([]) ->
|
||||
random:seed(os:timestamp()),
|
||||
emqttd:seed_now(),
|
||||
ets:new(?STATS_TAB, [set, public, named_table, {write_concurrency, true}]),
|
||||
Topics = ?SYSTOP_CLIENTS ++ ?SYSTOP_SESSIONS ++ ?SYSTOP_PUBSUB ++ ?SYSTOP_RETAINED,
|
||||
ets:insert(?STATS_TAB, [{Topic, 0} || Topic <- Topics]),
|
||||
|
|
Loading…
Reference in New Issue