diff options
author | Micael Karlberg <[email protected]> | 2019-08-01 18:43:04 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2019-08-01 18:43:04 +0200 |
commit | 2c6fa6c21cc373f67bddef658b53fd8ababff127 (patch) | |
tree | 342ecefab3d51451d9ffaa89b1482e351bf3154c /lib | |
parent | 412b9aee0f4529f6708040f060f77221022f4c20 (diff) | |
parent | f115892d729fd919b77f85855735398e90f801f0 (diff) | |
download | otp-2c6fa6c21cc373f67bddef658b53fd8ababff127.tar.gz otp-2c6fa6c21cc373f67bddef658b53fd8ababff127.tar.bz2 otp-2c6fa6c21cc373f67bddef658b53fd8ababff127.zip |
Merge branch 'bmk/snmp/20190731/correct_top_sup_stop' into maint
Diffstat (limited to 'lib')
-rw-r--r-- | lib/snmp/src/agent/snmpa_supervisor.erl | 35 | ||||
-rw-r--r-- | lib/snmp/src/manager/snmpm_supervisor.erl | 7 |
2 files changed, 38 insertions, 4 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) ]. diff --git a/lib/snmp/src/manager/snmpm_supervisor.erl b/lib/snmp/src/manager/snmpm_supervisor.erl index 0061488f54..bc66025c6f 100644 --- a/lib/snmp/src/manager/snmpm_supervisor.erl +++ b/lib/snmp/src/manager/snmpm_supervisor.erl @@ -38,6 +38,7 @@ %%%------------------------------------------------------------------- %%% API %%%------------------------------------------------------------------- + start_link(Type, Opts) -> ?d("start_link -> entry with" "~n Opts: ~p", [Opts]), @@ -62,17 +63,17 @@ stop(Timeout) -> %% 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 unly way...but since this function is +%% So, here we do it the really ugly way...but since this function is %% intended for testing (mostly)... stop(Pid, Timeout) when (Timeout =:= 0) -> ?d("stop -> Pid: ~p", [Pid]), - sys:terminate(whereis(?SERVER), shutdown), + sys:terminate(Pid, shutdown), ?d("stop -> stopped", []), ok; stop(Pid, Timeout) -> ?d("stop -> Pid: ~p", [Pid]), MRef = erlang:monitor(process, Pid), - sys:terminate(whereis(?SERVER), shutdown), + sys:terminate(Pid, shutdown), receive {'DOWN', MRef, process, Pid, _} -> ?d("stop -> stopped", []), |