aboutsummaryrefslogtreecommitdiffstats
path: root/lib/snmp/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/snmp/src')
-rw-r--r--lib/snmp/src/agent/snmp_community_mib.erl10
-rw-r--r--lib/snmp/src/agent/snmp_generic.erl18
-rw-r--r--lib/snmp/src/agent/snmp_standard_mib.erl13
-rw-r--r--lib/snmp/src/agent/snmp_target_mib.erl13
-rw-r--r--lib/snmp/src/agent/snmp_user_based_sm_mib.erl12
-rw-r--r--lib/snmp/src/agent/snmp_view_based_acm_mib.erl11
-rw-r--r--lib/snmp/src/agent/snmpa_mpd.erl10
-rw-r--r--lib/snmp/src/agent/snmpa_trap.erl17
-rw-r--r--lib/snmp/src/agent/snmpa_usm.erl22
-rw-r--r--lib/snmp/src/app/snmp_internal.hrl11
-rw-r--r--lib/snmp/src/compile/Makefile4
-rw-r--r--lib/snmp/src/compile/snmpc.erl11
-rw-r--r--lib/snmp/src/manager/snmpm_config.erl33
-rw-r--r--lib/snmp/src/manager/snmpm_mpd.erl14
-rw-r--r--lib/snmp/src/manager/snmpm_net_if.erl17
-rw-r--r--lib/snmp/src/manager/snmpm_server.erl35
-rw-r--r--lib/snmp/src/misc/snmp_conf.erl19
-rw-r--r--lib/snmp/src/misc/snmp_config.erl91
18 files changed, 194 insertions, 167 deletions
diff --git a/lib/snmp/src/agent/snmp_community_mib.erl b/lib/snmp/src/agent/snmp_community_mib.erl
index 9fd7b30f9f..984b0bcee1 100644
--- a/lib/snmp/src/agent/snmp_community_mib.erl
+++ b/lib/snmp/src/agent/snmp_community_mib.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1999-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1999-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -206,10 +206,10 @@ do_add_community(Community) ->
{error, create_failed}
end
catch
- {error, Reason} ->
- {error, Reason};
- Class:Reason ->
- {error, {Class, Reason, erlang:get_stacktrace()}}
+ throw:{error, _} = ERROR ->
+ ERROR;
+ C:E:S ->
+ {error, {C, E, S}}
end.
%% FIXME: does not work with mnesia
diff --git a/lib/snmp/src/agent/snmp_generic.erl b/lib/snmp/src/agent/snmp_generic.erl
index e67a1b3c80..26a0dd0648 100644
--- a/lib/snmp/src/agent/snmp_generic.erl
+++ b/lib/snmp/src/agent/snmp_generic.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2017. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -421,12 +421,12 @@ table_check_status(NameDb, Col, ?'RowStatus_createAndGo', RowIndex, Cols) ->
_Found -> {inconsistentValue, Col}
end
catch
- _:_Reason ->
+ _:_E:_S ->
?vtrace(
"failed construct row (createAndGo): "
- " n Reason: ~p"
- " n Stack: ~p",
- [_Reason, erlang:get_stacktrace()]),
+ " n Error: ~p"
+ " n Stack: ~p",
+ [_E, _S]),
{noCreation, Col} % Bad RowIndex
end;
true -> {inconsistentValue, Col}
@@ -441,12 +441,12 @@ table_check_status(NameDb, Col, ?'RowStatus_createAndWait', RowIndex, Cols) ->
_Row ->
{noError, 0}
catch
- _:_Reason ->
+ _:_E:_S ->
?vtrace(
"failed construct row (createAndWait): "
- " n Reason: ~p"
- " n Stack: ~p",
- [_Reason, erlang:get_stacktrace()]),
+ " n Error: ~p"
+ " n Stack: ~p",
+ [_E, _S]),
{noCreation, Col} % Bad RowIndex
end;
true -> {inconsistentValue, Col}
diff --git a/lib/snmp/src/agent/snmp_standard_mib.erl b/lib/snmp/src/agent/snmp_standard_mib.erl
index bfe471178d..679d2657c6 100644
--- a/lib/snmp/src/agent/snmp_standard_mib.erl
+++ b/lib/snmp/src/agent/snmp_standard_mib.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2015. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
-include("snmp_types.hrl").
-include("STANDARD-MIB.hrl").
+-include("snmpa_internal.hrl").
-define(VMODULE,"STANDARD-MIB").
-include("snmp_verbosity.hrl").
@@ -547,10 +548,12 @@ dummy(_Op) -> ok.
%%-----------------------------------------------------------------
snmp_set_serial_no(new) ->
snmp_generic:variable_func(new, {snmpSetSerialNo, volatile}),
- random:seed(erlang:phash2([node()]),
- erlang:monotonic_time(),
- erlang:unique_integer()),
- Val = random:uniform(2147483648) - 1,
+ ?SNMP_RAND_SEED(),
+ %% rand:seed(exrop,
+ %% {erlang:phash2([node()]),
+ %% erlang:monotonic_time(),
+ %% erlang:unique_integer()}),
+ Val = rand:uniform(2147483648) - 1,
snmp_generic:variable_func(set, Val, {snmpSetSerialNo, volatile});
snmp_set_serial_no(delete) ->
diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl
index e65fa7f340..22fd3acb84 100644
--- a/lib/snmp/src/agent/snmp_target_mib.erl
+++ b/lib/snmp/src/agent/snmp_target_mib.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1998-2015. All Rights Reserved.
+%% Copyright Ericsson AB 1998-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@
-define(VMODULE,"TARGET-MIB").
-include("snmp_verbosity.hrl").
+-include("snmpa_internal.hrl").
%% Column not accessible via SNMP - needed when the agent sends informs
@@ -673,10 +674,12 @@ snmpTargetSpinLock(print) ->
snmpTargetSpinLock(new) ->
snmp_generic:variable_func(new, {snmpTargetSpinLock, volatile}),
- random:seed(erlang:phash2([node()]),
- erlang:monotonic_time(),
- erlang:unique_integer()),
- Val = random:uniform(2147483648) - 1,
+ ?SNMP_RAND_SEED(),
+ %% rand:seed(exrop,
+ %% {erlang:phash2([node()]),
+ %% erlang:monotonic_time(),
+ %% erlang:unique_integer()}),
+ Val = rand:uniform(2147483648) - 1,
snmp_generic:variable_func(set, Val, {snmpTargetSpinLock, volatile});
snmpTargetSpinLock(delete) ->
diff --git a/lib/snmp/src/agent/snmp_user_based_sm_mib.erl b/lib/snmp/src/agent/snmp_user_based_sm_mib.erl
index f6e4fd3951..4842669fa4 100644
--- a/lib/snmp/src/agent/snmp_user_based_sm_mib.erl
+++ b/lib/snmp/src/agent/snmp_user_based_sm_mib.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1999-2015. All Rights Reserved.
+%% Copyright Ericsson AB 1999-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -440,10 +440,12 @@ usmUserSpinLock(print) ->
usmUserSpinLock(new) ->
snmp_generic:variable_func(new, {usmUserSpinLock, volatile}),
- random:seed(erlang:phash2([node()]),
- erlang:monotonic_time(),
- erlang:unique_integer()),
- Val = random:uniform(2147483648) - 1,
+ ?SNMP_RAND_SEED(),
+ %% rand:seed(exrop,
+ %% {erlang:phash2([node()]),
+ %% erlang:monotonic_time(),
+ %% erlang:unique_integer()}),
+ Val = rand:uniform(2147483648) - 1,
snmp_generic:variable_func(set, Val, {usmUserSpinLock, volatile});
usmUserSpinLock(delete) ->
diff --git a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl
index c6eeb7cea2..56b5d96142 100644
--- a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl
+++ b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl
@@ -48,6 +48,7 @@
-include("SNMPv2-TC.hrl").
-include("SNMP-VIEW-BASED-ACM-MIB.hrl").
-include("snmpa_vacm.hrl").
+-include("snmpa_internal.hrl").
-define(VMODULE,"VACM-MIB").
@@ -860,10 +861,12 @@ vacmViewSpinLock(print) ->
vacmViewSpinLock(new) ->
snmp_generic:variable_func(new, volatile_db(vacmViewSpinLock)),
- random:seed(erlang:phash2([node()]),
- erlang:monotonic_time(),
- erlang:unique_integer()),
- Val = random:uniform(2147483648) - 1,
+ ?SNMP_RAND_SEED(),
+ %% rand:seed(exrop,
+ %% {erlang:phash2([node()]),
+ %% erlang:monotonic_time(),
+ %% erlang:unique_integer()}),
+ Val = rand:uniform(2147483648) - 1,
snmp_generic:variable_func(set, Val, volatile_db(vacmViewSpinLock));
vacmViewSpinLock(delete) ->
diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl
index b440d57d03..2ec5dcb5e6 100644
--- a/lib/snmp/src/agent/snmpa_mpd.erl
+++ b/lib/snmp/src/agent/snmpa_mpd.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2015. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -76,11 +76,9 @@
init(Vsns) ->
?vlog("init -> entry with"
"~n Vsns: ~p", [Vsns]),
- random:seed(erlang:phash2([node()]),
- erlang:monotonic_time(),
- erlang:unique_integer()),
- ets:insert(snmp_agent_table, {msg_id, random:uniform(2147483647)}),
- ets:insert(snmp_agent_table, {req_id, random:uniform(2147483647)}),
+ ?SNMP_RAND_SEED(),
+ ets:insert(snmp_agent_table, {msg_id, rand:uniform(2147483647)}),
+ ets:insert(snmp_agent_table, {req_id, rand:uniform(2147483647)}),
init_counters(),
init_versions(Vsns, #state{}).
diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl
index d04b6a206e..f741c3aaa9 100644
--- a/lib/snmp/src/agent/snmpa_trap.erl
+++ b/lib/snmp/src/agent/snmpa_trap.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -364,13 +364,14 @@ send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, LocalEngineID,
LocalEngineID, ExtraInfo, NetIf)
end
catch
- T:E ->
- Info = [{args, [TrapRec, NotifyName, ContextName,
- Recv, Vbs, LocalEngineID, ExtraInfo, NetIf]},
- {tag, T},
- {err, E},
- {stacktrace, erlang:get_stacktrace()}],
- ?vlog("snmpa_trap:send_trap exception: ~p", [Info]),
+ C:E:S ->
+ Info = [{args, [TrapRec, NotifyName, ContextName,
+ Recv, Vbs, LocalEngineID, ExtraInfo, NetIf]},
+ {class, C},
+ {err, E},
+ {stacktrace, S}],
+ ?vlog("snmpa_trap:send_trap exception: "
+ "~n ~p", [Info]),
{error, {failed_sending_trap, Info}}
end.
diff --git a/lib/snmp/src/agent/snmpa_usm.erl b/lib/snmp/src/agent/snmpa_usm.erl
index fb616cd9ef..1debceae98 100644
--- a/lib/snmp/src/agent/snmpa_usm.erl
+++ b/lib/snmp/src/agent/snmpa_usm.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1999-2015. All Rights Reserved.
+%% Copyright Ericsson AB 1999-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -646,10 +646,12 @@ get_des_salt() ->
ets:insert(snmp_agent_table, {usm_des_salt, 0}),
0;
_ -> % it doesn't exist, initialize
- random:seed(erlang:phash2([node()]),
- erlang:monotonic_time(),
- erlang:unique_integer()),
- R = random:uniform(4294967295),
+ ?SNMP_RAND_SEED(),
+ %% rand:seed(exrop,
+ %% {erlang:phash2([node()]),
+ %% erlang:monotonic_time(),
+ %% erlang:unique_integer()}),
+ R = rand:uniform(4294967295),
ets:insert(snmp_agent_table, {usm_des_salt, R}),
R
end,
@@ -679,10 +681,12 @@ get_aes_salt() ->
ets:insert(snmp_agent_table, {usm_aes_salt, 0}),
0;
_ -> % it doesn't exist, initialize
- random:seed(erlang:phash2([node()]),
- erlang:monotonic_time(),
- erlang:unique_integer()),
- R = random:uniform(36893488147419103231),
+ ?SNMP_RAND_SEED(),
+ %% rand:seed(exrop,
+ %% {erlang:phash2([node()]),
+ %% erlang:monotonic_time(),
+ %% erlang:unique_integer()}),
+ R = rand:uniform(36893488147419103231),
ets:insert(snmp_agent_table, {usm_aes_salt, R}),
R
end,
diff --git a/lib/snmp/src/app/snmp_internal.hrl b/lib/snmp/src/app/snmp_internal.hrl
index 374767df15..f9a758ab7b 100644
--- a/lib/snmp/src/app/snmp_internal.hrl
+++ b/lib/snmp/src/app/snmp_internal.hrl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2006-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2006-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -25,7 +25,12 @@
-define(APPLICATION, snmp).
-endif.
--define(STACK(), erlang:get_stacktrace()).
+
+-define(SNMP_RAND_SEED_ALG, exrop).
+-define(SNMP_RAND_SEED(), rand:seed(?SNMP_RAND_SEED_ALG,
+ {erlang:phash2([node()]),
+ erlang:monotonic_time(),
+ erlang:unique_integer()})).
-define(snmp_info(C, F, A), ?snmp_msg(info_msg, C, F, A)).
-define(snmp_warning(C, F, A), ?snmp_msg(warning_msg, C, F, A)).
@@ -39,5 +44,3 @@
-endif. % -ifdef(snmp_internal).
-
-
diff --git a/lib/snmp/src/compile/Makefile b/lib/snmp/src/compile/Makefile
index 4093ffa9ca..d9678669a5 100644
--- a/lib/snmp/src/compile/Makefile
+++ b/lib/snmp/src/compile/Makefile
@@ -2,7 +2,7 @@
# %CopyrightBegin%
#
-# Copyright Ericsson AB 1997-2016. All Rights Reserved.
+# Copyright Ericsson AB 1997-2019. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -59,6 +59,8 @@ PARSER_TARGET = $(PARSER_MODULE).$(EMULATOR)
# ----------------------------------------------------
# FLAGS
# ----------------------------------------------------
+ERL_COMPILE_FLAGS += -pa $(ERL_TOP)/lib/snmp/ebin
+
ifeq ($(WARN_UNUSED_VARS),true)
ERL_COMPILE_FLAGS += +warn_unused_vars
endif
diff --git a/lib/snmp/src/compile/snmpc.erl b/lib/snmp/src/compile/snmpc.erl
index c810bfcd41..4249799195 100644
--- a/lib/snmp/src/compile/snmpc.erl
+++ b/lib/snmp/src/compile/snmpc.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2018. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
-export([init/3]).
-include_lib("stdlib/include/erl_compile.hrl").
+-include_lib("snmp/src/app/snmp_internal.hrl").
-include("snmp_types.hrl").
-include("snmpc.hrl").
-include("snmpc_lib.hrl").
@@ -413,9 +414,11 @@ get_verbosity(Options) ->
%%----------------------------------------------------------------------
init(From, MibFileName, Options) ->
- random:seed(erlang:phash2([node()]),
- erlang:monotonic_time(),
- erlang:unique_integer()),
+ ?SNMP_RAND_SEED(),
+ %% rand:seed(exrop,
+ %% {erlang:phash2([node()]),
+ %% erlang:monotonic_time(),
+ %% erlang:unique_integer()}),
put(options, Options),
put(verbosity, get_verbosity(Options)),
put(description, get_description(Options)),
diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl
index 118cdcd1df..cd9fecd4d4 100644
--- a/lib/snmp/src/manager/snmpm_config.erl
+++ b/lib/snmp/src/manager/snmpm_config.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2004-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2004-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -479,10 +479,7 @@ agent_info(Domain, Address, Item) when is_atom(Domain) ->
NAddress ->
do_agent_info(Domain, NAddress, Item)
catch
- _Thrown ->
- %% p(?MODULE_STRING":agent_info(~p, ~p, ~p) throwed ~p at.~n"
- %% " ~p",
- %% [Domain, Address, Item, _Thrown, erlang:get_stacktrace()]),
+ _C:_E:_S ->
{error, not_found}
end;
agent_info(Ip, Port, Item) when is_integer(Port) ->
@@ -493,10 +490,7 @@ agent_info(Ip, Port, Item) when is_integer(Port) ->
Address ->
do_agent_info(Domain, Address, Item)
catch
- _Thrown ->
- %% p(?MODULE_STRING":agent_info(~p, ~p, ~p) throwed ~p at.~n"
- %% " ~p",
- %% [Ip, Port, Item, _Thrown, erlang:get_stacktrace()]),
+ _C:_E:_S ->
{error, not_found}
end.
@@ -1688,9 +1682,10 @@ read_agents_config_file(Dir) ->
Check = fun check_agent_config/2,
try read_file(Dir, "agents.conf", Order, Check, [])
catch
- throw:Error ->
- ?vlog("agent config error: ~p", [Error]),
- erlang:raise(throw, Error, erlang:get_stacktrace())
+ throw:E:S ->
+ ?vlog("agent config error: "
+ "~n ~p", [E]),
+ erlang:raise(throw, E, S)
end.
check_agent_config(Agent, State) ->
@@ -1935,9 +1930,10 @@ read_users_config_file(Dir) ->
Check = fun (User, State) -> {check_user_config(User), State} end,
try read_file(Dir, "users.conf", Order, Check, [])
catch
- throw:Error ->
- ?vlog("failure reading users config file: ~n ~p", [Error]),
- erlang:raise(throw, Error, erlang:get_stacktrace())
+ throw:E:S ->
+ ?vlog("failure reading users config file: "
+ "~n ~p", [E]),
+ erlang:raise(throw, E, S)
end.
check_user_config({Id, Mod, Data}) ->
@@ -2351,10 +2347,11 @@ read_file(Dir, FileName, Order, Check, Default) ->
read_file(Dir, FileName, Order, Check) ->
try snmp_conf:read(filename:join(Dir, FileName), Order, Check)
catch
- throw:{error, Reason} = Error
+ throw:{error, Reason} = E:S
when element(1, Reason) =:= failed_open ->
- error_msg("failed reading config from ~s: ~p", [FileName, Reason]),
- erlang:raise(throw, Error, erlang:get_stacktrace())
+ error_msg("failed reading config from ~s: "
+ "~n ~p", [FileName, Reason]),
+ erlang:raise(throw, E, S)
end.
%%--------------------------------------------------------------------
diff --git a/lib/snmp/src/manager/snmpm_mpd.erl b/lib/snmp/src/manager/snmpm_mpd.erl
index 191dc2c281..8d0a7918a6 100644
--- a/lib/snmp/src/manager/snmpm_mpd.erl
+++ b/lib/snmp/src/manager/snmpm_mpd.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2004-2015. All Rights Reserved.
+%% Copyright Ericsson AB 2004-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -68,11 +68,13 @@
%%%-----------------------------------------------------------------
init(Vsns) ->
?vdebug("init -> entry with ~p", [Vsns]),
- random:seed(erlang:phash2([node()]),
- erlang:monotonic_time(),
- erlang:unique_integer()),
- snmpm_config:cre_counter(msg_id, random:uniform(2147483647)),
- snmpm_config:cre_counter(req_id, random:uniform(2147483647)),
+ ?SNMP_RAND_SEED(),
+ %% rand:seed(exrop,
+ %% {erlang:phash2([node()]),
+ %% erlang:monotonic_time(),
+ %% erlang:unique_integer()}),
+ snmpm_config:cre_counter(msg_id, rand:uniform(2147483647)),
+ snmpm_config:cre_counter(req_id, rand:uniform(2147483647)),
init_counters(),
State = init_versions(Vsns, #state{}),
init_usm(State#state.v3),
diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl
index 29216f9d6a..184f782860 100644
--- a/lib/snmp/src/manager/snmpm_net_if.erl
+++ b/lib/snmp/src/manager/snmpm_net_if.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2004-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2004-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -182,11 +182,9 @@ worker(Worker, Failer, #state{log = Log} = State) ->
%% Winds up in handle_info {'DOWN', ...}
erlang:exit({net_if_worker, Result})
catch
- Class:Reason ->
+ C:E:S ->
%% Winds up in handle_info {'DOWN', ...}
- erlang:exit(
- {net_if_worker, Failer,
- Class, Reason, erlang:get_stacktrace()})
+ erlang:exit({net_if_worker, Failer, C, E, S})
end
end,
[monitor]).
@@ -983,11 +981,10 @@ udp_send(Sock, To, Msg) ->
error_msg("failed sending message to ~p:~p:~n"
" ~p",[IpAddr, IpPort, Reason])
catch
- error:Error ->
- error_msg("failed sending message to ~p:~p:~n"
- " error:~p~n"
- " ~p",
- [IpAddr, IpPort, Error, erlang:get_stacktrace()])
+ error:E:S ->
+ error_msg("failed sending message to ~p:~p:"
+ "~n ~p"
+ "~n ~p", [IpAddr, IpPort, E, S])
end.
sz(B) when is_binary(B) ->
diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl
index c8d7fa1e8b..a6ca2b2b14 100644
--- a/lib/snmp/src/manager/snmpm_server.erl
+++ b/lib/snmp/src/manager/snmpm_server.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2004-2015. All Rights Reserved.
+%% Copyright Ericsson AB 2004-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -1755,9 +1755,10 @@ handle_error(_UserId, Mod, Reason, ReqId, Data, _State) ->
Mod:handle_error(ReqId, Reason, Data)
end
catch
- T:E ->
+ C:E:S ->
CallbackArgs = [ReqId, Reason, Data],
- handle_invalid_result(handle_error, CallbackArgs, T, E)
+ handle_invalid_result(handle_error, CallbackArgs,
+ C, E, S)
end
end,
handle_callback(F),
@@ -1948,9 +1949,10 @@ handle_pdu(
Mod:handle_pdu(TargetName, ReqId, SnmpResponse, Data)
end
catch
- T:E ->
+ C:E:S ->
CallbackArgs = [TargetName, ReqId, SnmpResponse, Data],
- handle_invalid_result(handle_pdu, CallbackArgs, T, E)
+ handle_invalid_result(handle_pdu, CallbackArgs,
+ C, E, S)
end
end,
handle_callback(F),
@@ -2119,10 +2121,10 @@ do_handle_agent(DefUserId, DefMod,
"<~p,~p>: ~n~w", [Type, Domain, Addr, SnmpInfo])
end;
- T:E ->
+ C:E:S ->
CallbackArgs =
[Domain_or_Ip, Addr_or_Port, Type, SnmpInfo, DefData],
- handle_invalid_result(handle_agent, CallbackArgs, T, E)
+ handle_invalid_result(handle_agent, CallbackArgs, C, E, S)
end.
@@ -2331,8 +2333,8 @@ do_handle_trap(
handle_invalid_result(handle_trap, CallbackArgs, InvalidResult)
catch
- T:E ->
- handle_invalid_result(handle_trap, CallbackArgs, T, E)
+ C:E:S ->
+ handle_invalid_result(handle_trap, CallbackArgs, C, E, S)
end.
@@ -2523,8 +2525,8 @@ do_handle_inform(
reply
catch
- T:E ->
- handle_invalid_result(handle_inform, CallbackArgs, T, E),
+ C:E:S ->
+ handle_invalid_result(handle_inform, CallbackArgs, C, E, S),
reply
end,
@@ -2837,8 +2839,8 @@ do_handle_report(
reply
catch
- T:E ->
- handle_invalid_result(handle_report, CallbackArgs, T, E),
+ C:E:S ->
+ handle_invalid_result(handle_report, CallbackArgs, C, E, S),
reply
end.
@@ -2855,15 +2857,14 @@ handle_callback(F) ->
-handle_invalid_result(Func, Args, T, E) ->
- Stacktrace = ?STACK(),
+handle_invalid_result(Func, Args, C, E, S) ->
error_msg("Callback function failed: "
"~n Function: ~p"
"~n Args: ~p"
- "~n Error Type: ~p"
+ "~n Class: ~p"
"~n Error: ~p"
"~n Stacktrace: ~p",
- [Func, Args, T, E, Stacktrace]).
+ [Func, Args, C, E, S]).
handle_invalid_result(Func, Args, InvalidResult) ->
error_msg("Callback function returned invalid result: "
diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl
index 513616a285..d73291764d 100644
--- a/lib/snmp/src/misc/snmp_conf.erl
+++ b/lib/snmp/src/misc/snmp_conf.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -236,15 +236,16 @@ read_check(File, Check, [{StartLine, Row, EndLine}|Lines], State, Res) ->
" NewRow: ~p~n", [NewRow]),
read_check(File, Check, Lines, NewState, [NewRow | Res])
catch
- {error, Reason} ->
- ?vtrace("read_check -> error:~n"
- " Reason: ~p", [Reason]),
+ throw:{error, Reason} ->
+ ?vtrace("read_check -> error:"
+ "~n Reason: ~p", [Reason]),
error({failed_check, File, StartLine, EndLine, Reason});
- Class:Reason ->
- Error = {Class,Reason,erlang:get_stacktrace()},
- ?vtrace("read_check -> failure:~n"
- " Error: ~p", [Error]),
- error({failed_check, File, StartLine, EndLine, Error})
+ C:E:S ->
+ ?vtrace("read_check -> failure:"
+ "~n Class: ~p"
+ "~n Error: ~p"
+ "~n Stack: ~p", [C, E, S]),
+ error({failed_check, File, StartLine, EndLine, {C, E, S}})
end.
open_file(File) ->
diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl
index 45661b71a7..26e85897f4 100644
--- a/lib/snmp/src/misc/snmp_config.erl
+++ b/lib/snmp/src/misc/snmp_config.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -2573,15 +2573,17 @@ write_config_file(Dir, FileName, Order, Check, Write, Entries)
Error
end
catch
- Error ->
- S = erlang:get_stacktrace(),
- d("File write of ~s throwed: ~p~n ~p~n",
- [FileName, Error, S]),
- Error;
- C:E ->
- S = erlang:get_stacktrace(),
- d("File write of ~s exception: ~p:~p~n ~p~n",
- [FileName,C,E,S]),
+ throw:E:S ->
+ d("File write of ~s throwed: "
+ "~n ~p"
+ "~n ~p"
+ "~n", [FileName, E, S]),
+ E;
+ C:E:S ->
+ d("File write of ~s exception: "
+ "~n ~p:~p"
+ "~n ~p"
+ "~n", [FileName, C, E, S]),
{error, {failed_write, Dir, FileName, {C, E, S}}}
end.
@@ -2590,16 +2592,18 @@ write_config_file(Dir, FileName, Write, Entries, Fd) ->
ok ->
close_config_file(Dir, FileName, Fd)
catch
- Error ->
- S = erlang:get_stacktrace(),
- d("File write of ~s throwed: ~p~n ~p~n",
- [FileName, Error, S]),
+ throw:E:S ->
+ d("File write of ~s throwed: "
+ "~n ~p"
+ "~n ~p"
+ "~n", [FileName, E, S]),
close_config_file(Dir, FileName, Fd),
- Error;
- C:E ->
- S = erlang:get_stacktrace(),
- d("File write of ~s exception: ~p:~p~n ~p~n",
- [FileName,C,E,S]),
+ E;
+ C:E:S ->
+ d("File write of ~s exception: "
+ "~n ~p:~p"
+ "~n ~p"
+ "~n", [FileName, C, E, S]),
close_config_file(Dir, FileName, Fd),
{error, {failed_write, Dir, FileName, {C, E, S}}}
end.
@@ -2661,16 +2665,18 @@ append_config_file(Dir, FileName, Order, Check, Write, Entries, Fd) ->
ok ->
close_config_file(Dir, FileName, Fd)
catch
- Error ->
- S = erlang:get_stacktrace(),
- d("File append of ~s throwed: ~p~n ~p~n",
- [FileName, Error, S]),
+ throw:E:S ->
+ d("File append of ~s throwed: "
+ "~n ~p"
+ "~n ~p"
+ "~n", [FileName, E, S]),
close_config_file(Dir, FileName, Fd),
- Error;
- C:E ->
- S = erlang:get_stacktrace(),
- d("File append of ~s exception: ~p:~p~n ~p~n",
- [FileName,C,E,S]),
+ E;
+ C:E:S ->
+ d("File append of ~s exception: "
+ "~n ~p:~p"
+ "~n ~p"
+ "~n", [FileName, C, E, S]),
close_config_file(Dir, FileName, Fd),
{error, {failed_append, Dir, FileName, {C, E, S}}}
end.
@@ -2702,16 +2708,18 @@ read_config_file(Dir, FileName, Order, Check)
SortedLines = sort_lines(Lines, Order),
{ok, verify_lines(SortedLines, Check, undefined, [])}
catch
- Error ->
- S = erlang:get_stacktrace(),
- d("File read of ~s throwed: ~p~n ~p~n",
- [FileName, Error, S]),
- {error, Error};
- T:E ->
- S = erlang:get_stacktrace(),
- d("File read of ~s exception: ~p:~p~n ~p~n",
- [FileName,T,E,S]),
- {error, {failed_read, Dir, FileName, {T, E, S}}}
+ throw:E:S ->
+ d("File read of ~s throwed: "
+ "~n ~p"
+ "~n ~p"
+ "~n", [FileName, E, S]),
+ {error, E};
+ C:E:S ->
+ d("File read of ~s exception: "
+ "~n ~p:~p"
+ "~n ~p"
+ "~n", [FileName, C, E, S]),
+ {error, {failed_read, Dir, FileName, {C, E, S}}}
after
file:close(Fd)
end;
@@ -2760,11 +2768,10 @@ verify_lines(
{{ok, NewTerm}, NewState} ->
verify_lines(Lines, Check, NewState, [NewTerm|Acc])
catch
- {error, Reason} ->
+ throw:{error, Reason}:_ ->
throw({failed_check, StartLine, EndLine, Reason});
- C:R ->
- S = erlang:get_stacktrace(),
- throw({failed_check, StartLine, EndLine, {C, R, S}})
+ C:E:S ->
+ throw({failed_check, StartLine, EndLine, {C, E, S}})
end.