LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0595-Add-start_distribution-to-kernel-environment.patch of Package erlang (Project home:Ledest:erlang:20)

From c3391bb822f0516975b293bc220e1a44cdb8bc0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@plataformatec.com.br>
Date: Wed, 9 Jan 2019 12:24:17 +0100
Subject: [PATCH] Add start_distribution to kernel environment

Sometimes you may want to start Erlang without any
of its distribution services. This commit adds an
environment configuration that allows so.

Because the servers we don't start here are a subset
of the servers not started on minimal mode, we do
have a guarantee that the system can still operate
as the system operates without those apps on minimal
mode.
---
 lib/kernel/doc/src/kernel_app.xml       |  8 ++++
 lib/kernel/src/kernel.erl               | 72 ++++++++++++++++++---------------
 lib/kernel/test/kernel_config_SUITE.erl | 21 ++++++----
 3 files changed, 62 insertions(+), 39 deletions(-)

diff --git a/lib/kernel/doc/src/kernel_app.xml b/lib/kernel/doc/src/kernel_app.xml
index 15dbdb47dc..78c7319e43 100644
--- a/lib/kernel/doc/src/kernel_app.xml
+++ b/lib/kernel/doc/src/kernel_app.xml
@@ -369,6 +369,14 @@ MaxT = TickTime + TickTime / 4</code>
           performed. This option ensures that <c>global</c> is
           synchronized.</p>
       </item>
+      <tag><c>start_distribution = true | false</c></tag>
+      <item>
+        <p>Starts all distribution services, such as <c>rpc</c>,
+          <c>global</c>, and <c>net_kernel</c> if the parameter is
+          <c>true</c>. This parameter is to be set to <c>false</c>
+          for systems who want to disable all distribution functionality.</p>
+        <p>Defaults to <c>true</c>.</p>
+      </item>
       <tag><c>start_dist_ac = true | false</c></tag>
       <item>
         <p>Starts the <c>dist_ac</c> server if the parameter is
diff --git a/lib/kernel/src/kernel.erl b/lib/kernel/src/kernel.erl
index c68d04e279..111d103df2 100644
--- a/lib/kernel/src/kernel.erl
+++ b/lib/kernel/src/kernel.erl
@@ -150,26 +150,11 @@ init([]) ->
         {ok, [["minimal"]]} ->
             {ok, {SupFlags, [Code, File, StdError, User, Config, SafeSup]}};
         _ ->
-            Rpc = #{id => rex,
-                    start => {rpc, start_link, []},
-                    restart => permanent,
-                    shutdown => 2000,
-                    type => worker,
-                    modules => [rpc]},
-
-            Global = #{id => global_name_server,
-                       start => {global, start_link, []},
-                       restart => permanent,
-                       shutdown => 2000,
-                       type => worker,
-                       modules => [global]},
-
-            GlGroup = #{id => global_group,
-                        start => {global_group,start_link,[]},
-                        restart => permanent,
-                        shutdown => 2000,
-                        type => worker,
-                        modules => [global_group]},
+            DistChildren =
+		case application:get_env(kernel, start_distribution) of
+		    {ok, false} -> [];
+		    _ -> start_distribution()
+		end,
 
             InetDb = #{id => inet_db,
                        start => {inet_db, start_link, []},
@@ -178,13 +163,6 @@ init([]) ->
                        type => worker,
                        modules => [inet_db]},
 
-            NetSup = #{id => net_sup,
-                       start => {erl_distribution, start_link, []},
-                       restart => permanent,
-                       shutdown => infinity,
-                       type => supervisor,
-                       modules => [erl_distribution]},
-
             SigSrv = #{id => erl_signal_server,
                        start => {gen_event, start_link, [{local, erl_signal_server}]},
                        restart => permanent,
@@ -192,14 +170,11 @@ init([]) ->
                        type => worker,
                        modules => dynamic},
 
-            DistAC = start_dist_ac(),
-
             Timer = start_timer(),
 
             {ok, {SupFlags,
-                  [Code, Rpc, Global, InetDb | DistAC] ++
-                  [NetSup, GlGroup, File, SigSrv,
-                   StdError, User, Config, SafeSup] ++ Timer}}
+                  [Code, InetDb | DistChildren] ++
+                  [File, SigSrv, StdError, User, Config, SafeSup] ++ Timer}}
     end;
 init(safe) ->
     SupFlags = #{strategy => one_for_one,
@@ -218,6 +193,39 @@ init(safe) ->
 
     {ok, {SupFlags, Boot ++ DiskLog ++ Pg2}}.
 
+start_distribution() ->
+    Rpc = #{id => rex,
+            start => {rpc, start_link, []},
+            restart => permanent,
+            shutdown => 2000,
+            type => worker,
+            modules => [rpc]},
+
+    Global = #{id => global_name_server,
+               start => {global, start_link, []},
+               restart => permanent,
+               shutdown => 2000,
+               type => worker,
+               modules => [global]},
+
+    DistAC = start_dist_ac(),
+
+    NetSup = #{id => net_sup,
+               start => {erl_distribution, start_link, []},
+               restart => permanent,
+               shutdown => infinity,
+               type => supervisor,
+               modules => [erl_distribution]},
+
+    GlGroup = #{id => global_group,
+                start => {global_group,start_link,[]},
+                restart => permanent,
+                shutdown => 2000,
+                type => worker,
+                modules => [global_group]},
+
+    [Rpc, Global | DistAC] ++ [NetSup, GlGroup].
+
 start_dist_ac() ->
     Spec = [#{id => dist_ac,
               start => {dist_ac,start_link,[]},
diff --git a/lib/kernel/test/kernel_config_SUITE.erl b/lib/kernel/test/kernel_config_SUITE.erl
index 9207025a2c..57c44c2498 100644
--- a/lib/kernel/test/kernel_config_SUITE.erl
+++ b/lib/kernel/test/kernel_config_SUITE.erl
@@ -21,7 +21,8 @@
 
 -include_lib("common_test/include/ct.hrl").
 
--export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2, sync/1]).
+-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2,
+	 start_distribution_false/1, sync/1]).
 
 -export([init_per_suite/1, end_per_suite/1]).
 
@@ -30,7 +31,7 @@ suite() ->
      {timetrap,{minutes,2}}].
 
 all() -> 
-    [sync].
+    [sync, start_distribution_false].
 
 groups() -> 
     [].
@@ -59,12 +60,9 @@ from(H, [H | T]) -> T;
 from(H, [_ | T]) -> from(H, T);
 from(_, []) -> [].
 
-%%-----------------------------------------------------------------
-%% Test suite for sync_nodes.   This is quite tricky.
-%%
+%% Test sync_nodes. This is quite tricky.
 %% Should be started in a CC view with:
 %% erl -sname XXX where XX not in [cp1, cp2]
-%%-----------------------------------------------------------------
 sync(Conf) when is_list(Conf) ->
     %% Write a config file
     Dir = proplists:get_value(priv_dir,Conf),
@@ -106,9 +104,18 @@ wait_for_node(Node) ->
 	_Other -> wait_for_node(Node)
     end.
 
-
 stop_node(Node) ->
     M = list_to_atom(lists:concat([Node,
 				   [$@],
 				   from($@,atom_to_list(node()))])),
     rpc:cast(M, erlang, halt, []).
+
+start_distribution_false(Config) when is_list(Config) ->
+    %% When distribution is disabled, -sname/-name has no effect
+    Str = os:cmd(ct:get_progname()
+		 ++ " -kernel start_distribution false"
+		 ++ " -sname no_distribution"
+		 ++ " -eval \"erlang:display(node())\""
+		 ++ " -noshell -s erlang halt"),
+    "'nonode@nohost'" ++ _ = Str,
+    ok.
-- 
2.16.4