diff options
author | Richard Carlsson <[email protected]> | 2016-10-29 16:23:09 +0200 |
---|---|---|
committer | Richard Carlsson <[email protected]> | 2016-10-29 16:23:09 +0200 |
commit | cd8438832471e7444eec7b78cd1aaee6779cc28a (patch) | |
tree | 527d879440a9b8bb94e611a40020826cb39e5b45 /lib/mnesia | |
parent | c49194c9239c0dcad17b902b6638edf53bb69c6c (diff) | |
download | otp-cd8438832471e7444eec7b78cd1aaee6779cc28a.tar.gz otp-cd8438832471e7444eec7b78cd1aaee6779cc28a.tar.bz2 otp-cd8438832471e7444eec7b78cd1aaee6779cc28a.zip |
Make a separate application module for Mnesia
To separate concerns and reduce confusion, avoid implementing two
behaviours in a single module. Make a single start_link() helper in
mnesia_sup and remove the unused mnesia_sup:start() utility function.
Diffstat (limited to 'lib/mnesia')
-rw-r--r-- | lib/mnesia/doc/src/Mnesia_chap3.xmlsrc | 2 | ||||
-rw-r--r-- | lib/mnesia/src/Makefile | 1 | ||||
-rw-r--r-- | lib/mnesia/src/mnesia.app.src | 5 | ||||
-rw-r--r-- | lib/mnesia/src/mnesia.erl | 1 | ||||
-rw-r--r-- | lib/mnesia/src/mnesia_app.erl | 41 | ||||
-rw-r--r-- | lib/mnesia/src/mnesia_sup.erl | 33 |
6 files changed, 53 insertions, 30 deletions
diff --git a/lib/mnesia/doc/src/Mnesia_chap3.xmlsrc b/lib/mnesia/doc/src/Mnesia_chap3.xmlsrc index 8f1a4366ee..ffda739dfa 100644 --- a/lib/mnesia/doc/src/Mnesia_chap3.xmlsrc +++ b/lib/mnesia/doc/src/Mnesia_chap3.xmlsrc @@ -348,7 +348,7 @@ skeppet %<input>erl -sname b -mnesia dir '"/ldisc/scratch/Mnesia.company"'</inpu <p>If the startup procedure fails, the function <seealso marker="mnesia#start/0">mnesia:start()</seealso> returns the cryptic tuple - <c>{error,{shutdown, {mnesia_sup,start,[normal,[]]}}}</c>. + <c>{error,{shutdown, {mnesia_sup,start_link,[normal,[]]}}}</c>. To get more information about the start failure, use command-line arguments <c>-boot start_sasl</c> as argument to the <c>erl</c> script.</p> diff --git a/lib/mnesia/src/Makefile b/lib/mnesia/src/Makefile index 08a00e6aba..5206e469a5 100644 --- a/lib/mnesia/src/Makefile +++ b/lib/mnesia/src/Makefile @@ -43,6 +43,7 @@ RELSYSDIR = $(RELEASE_PATH)/lib/mnesia-$(VSN) # ---------------------------------------------------- MODULES= \ mnesia \ + mnesia_app \ mnesia_backend_type \ mnesia_backup \ mnesia_bup \ diff --git a/lib/mnesia/src/mnesia.app.src b/lib/mnesia/src/mnesia.app.src index 006ad4bac1..af14826c90 100644 --- a/lib/mnesia/src/mnesia.app.src +++ b/lib/mnesia/src/mnesia.app.src @@ -3,6 +3,7 @@ {vsn, "%VSN%"}, {modules, [ mnesia, + mnesia_app, mnesia_backend_type, mnesia_backup, mnesia_bup, @@ -49,7 +50,5 @@ mnesia_tm ]}, {applications, [kernel, stdlib]}, - {mod, {mnesia_sup, []}}, + {mod, {mnesia_app, []}}, {runtime_dependencies, ["stdlib-2.0","kernel-3.0","erts-7.0"]}]}. - - diff --git a/lib/mnesia/src/mnesia.erl b/lib/mnesia/src/mnesia.erl index 5bf2fc2dc3..9c7321ee43 100644 --- a/lib/mnesia/src/mnesia.erl +++ b/lib/mnesia/src/mnesia.erl @@ -273,6 +273,7 @@ kill() -> ms() -> [ mnesia, + mnesia_app, mnesia_backup, mnesia_bup, mnesia_checkpoint, diff --git a/lib/mnesia/src/mnesia_app.erl b/lib/mnesia/src/mnesia_app.erl new file mode 100644 index 0000000000..4d89011db2 --- /dev/null +++ b/lib/mnesia/src/mnesia_app.erl @@ -0,0 +1,41 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 1996-2016. 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. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +-module(mnesia_app). + +-behaviour(application). + +-export([start/2, stop/1]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% application callback functions + +start(normal, Args) -> + case mnesia_sup:start_link(Args) of + {ok, Pid} -> + {ok, Pid, {normal, Args}}; + Error -> + Error + end; +start(_, _) -> + {error, badarg}. + +stop(_StartArgs) -> + ok. diff --git a/lib/mnesia/src/mnesia_sup.erl b/lib/mnesia/src/mnesia_sup.erl index 4aece81308..3e5792900b 100644 --- a/lib/mnesia/src/mnesia_sup.erl +++ b/lib/mnesia/src/mnesia_sup.erl @@ -23,39 +23,21 @@ -module(mnesia_sup). --behaviour(application). -behaviour(supervisor). --export([start/0, start/2, init/1, stop/1, start_event/0, kill/0]). +-export([start_link/1, init/1, start_event/0, kill/0]). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% application and suprvisor callback functions - -start(normal, Args) -> - SupName = {local,?MODULE}, - case supervisor:start_link(SupName, ?MODULE, [Args]) of - {ok, Pid} -> - {ok, Pid, {normal, Args}}; - Error -> - Error - end; -start(_, _) -> - {error, badarg}. - -start() -> - SupName = {local,?MODULE}, - supervisor:start_link(SupName, ?MODULE, []). +start_link(Args) -> + supervisor:start_link({local,?MODULE}, ?MODULE, [Args]). -stop(_StartArgs) -> - ok. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% supervisor callback functions -init([]) -> % Supervisor - init(); -init([[]]) -> % Application +init([[]]) -> init(); init(BadArg) -> {error, {badarg, BadArg}}. - + init() -> Flags = {one_for_all, 0, 3600}, % Should be rest_for_one policy @@ -124,4 +106,3 @@ ensure_dead(Name) -> timer:sleep(10), ensure_dead(Name) end. - |