From 92e37200fdfba41a625615b5b8e8308e363393aa Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 24 Feb 2012 15:29:04 +0100 Subject: [snmp/agent] Improve error handling while reading agent config files Improve error handling while reading agent config files. OTP-9943 --- lib/snmp/src/agent/snmp_community_mib.erl | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib/snmp/src/agent/snmp_community_mib.erl') diff --git a/lib/snmp/src/agent/snmp_community_mib.erl b/lib/snmp/src/agent/snmp_community_mib.erl index 77307aa7ad..d7d41aca31 100644 --- a/lib/snmp/src/agent/snmp_community_mib.erl +++ b/lib/snmp/src/agent/snmp_community_mib.erl @@ -28,6 +28,7 @@ -export([add_community/5, add_community/6, delete_community/1]). -export([check_community/1]). +-include("snmpa_internal.hrl"). -include("SNMP-COMMUNITY-MIB.hrl"). -include("SNMP-TARGET-MIB.hrl"). -include("SNMPv2-TC.hrl"). @@ -120,10 +121,17 @@ init_tabs(Comms) -> read_community_config_files(Dir) -> ?vdebug("read community config file",[]), - Gen = fun(_) -> ok end, - Filter = fun(Comms) -> Comms end, - Check = fun(Entry) -> check_community(Entry) end, - [Comms] = + FileName = "community.conf", + Gen = fun(D, Reason) -> + warning_msg("failed reading config file ~s" + "~n Config Dir: ~s" + "~n Reason: ~p", + [FileName, D, Reason]), + ok + end, + Filter = fun(Comms) -> Comms end, + Check = fun(Entry) -> check_community(Entry) end, + [Comms] = snmp_conf:read_files(Dir, [{Gen, Filter, Check, "community.conf"}]), Comms. @@ -601,5 +609,8 @@ set_sname(_) -> %% Keep it, if already set. error(Reason) -> throw({error, Reason}). +warning_msg(F, A) -> + ?snmpa_warning("[COMMUNITY-MIB]: " ++ F, A). + config_err(F, A) -> snmpa_error:config_err("[COMMUNITY-MIB]: " ++ F, A). -- cgit v1.2.3