diff options
author | Micael Karlberg <[email protected]> | 2019-07-31 19:08:50 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2019-07-31 19:08:50 +0200 |
commit | f115892d729fd919b77f85855735398e90f801f0 (patch) | |
tree | 040bbd84d502bab5435ef7b5ccfb6c410ba7654c /lib/snmp/src/agent | |
parent | 6c4ad85880375b242ac48a2bf439887f503ce203 (diff) | |
download | otp-f115892d729fd919b77f85855735398e90f801f0.tar.gz otp-f115892d729fd919b77f85855735398e90f801f0.tar.bz2 otp-f115892d729fd919b77f85855735398e90f801f0.zip |
[snmp] Fixed agent|manager top supervisor stop
Diffstat (limited to 'lib/snmp/src/agent')
-rw-r--r-- | lib/snmp/src/agent/snmpa_supervisor.erl | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/snmp/src/agent/snmpa_supervisor.erl b/lib/snmp/src/agent/snmpa_supervisor.erl index 2cb0556001..7d5c6da2c8 100644 --- a/lib/snmp/src/agent/snmpa_supervisor.erl +++ b/lib/snmp/src/agent/snmpa_supervisor.erl @@ -22,7 +22,7 @@ -behaviour(supervisor). %% External exports --export([start_link/2]). +-export([start_link/2, stop/0, stop/1]). -export([start_sub_sup/1, start_master_sup/1]). -export([start_sub_agent/3, stop_sub_agent/1]). @@ -91,6 +91,39 @@ start_link(master, Opts, {takeover, Node}) -> Else end. + +stop() -> + stop(0). + +stop(Timeout) -> + case whereis(?SERVER) of + Pid when is_pid(Pid) -> + stop(Pid, Timeout); + _ -> + not_running + end. + +%% For some unfathomable reason there is no "nice" way to stop +%% a supervisor. The "normal" way to do it is: +%% 1) exit(Pid, kill) (kaboom) +%% 2) If the caller is the *parent*: exit(Pid, shutdown) +%% So, here we do it the really ugly way...but since this function is +%% intended for testing (mostly)... +stop(Pid, Timeout) when (Timeout =:= 0) -> + sys:terminate(Pid, shutdown), + ok; +stop(Pid, Timeout) -> + MRef = erlang:monitor(process, Pid), + sys:terminate(Pid, shutdown), + receive + {'DOWN', MRef, process, Pid, _} -> + ok + after Timeout -> + erlang:demonitor(MRef, [flush]), + {error, timeout} + end. + + get_own_loaded_mibs() -> AgentInfo = snmpa:info(snmp_master_agent), [ Name || {Name, _, _} <- loaded_mibs(AgentInfo) ]. |