A new user interface for you! Read more...

File 0305-Don-t-save-included_applications-as-application-envi.patch of Package erlang

From a178e9545725455d064efd3f039c5052918544d5 Mon Sep 17 00:00:00 2001
From: Siri Hansen <siri@erlang.org>
Date: Fri, 4 May 2018 15:01:54 +0200
Subject: [PATCH] Don't save included_applications as application environment
 variable

During application load, the included_applications key from the .app
file would earlier be duplicated as an application environment
variable. Due to this, its value could be retrieved in any of the
following ways:

application:get_key(App,included_applications).
application:get_env(App,included_applications).

It would also be included in the resulting list from the following calls:

application:get_all_key(App).
application:get_all_env(App).

This commit removes the duplication, and included_applications will no
longer be returned by application:get_env/2 or application:get_all_env/1.

The reason for this change is mainly to avoid confusion, but also to
avoid the potensial inconsistency which would occur if the environment
variable was changed during runtime by calls to
application:put_env(App,included_applications,NewInclApps).
---
 lib/kernel/src/application_controller.erl | 12 +++---------
 lib/kernel/test/application_SUITE.erl     | 12 ++++--------
 2 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/lib/kernel/src/application_controller.erl b/lib/kernel/src/application_controller.erl
index b9cb722575..ff5df667b5 100644
--- a/lib/kernel/src/application_controller.erl
+++ b/lib/kernel/src/application_controller.erl
@@ -1272,9 +1272,7 @@ load(S, {ApplData, ApplEnv, IncApps, Descr, Id, Vsn, Apps}) ->
     NewEnv = merge_app_env(ApplEnv, ConfEnv),
     CmdLineEnv = get_cmd_env(Name),
     NewEnv2 = merge_app_env(NewEnv, CmdLineEnv),
-    NewEnv3 = keyreplaceadd(included_applications, 1, NewEnv2,
-			    {included_applications, IncApps}),
-    add_env(Name, NewEnv3),
+    add_env(Name, NewEnv2),
     Appl = #appl{name = Name, descr = Descr, id = Id, vsn = Vsn, 
 		 appl_data = ApplData, inc_apps = IncApps, apps = Apps},
     ets:insert(ac_tab, {{loaded, Name}, Appl}),
@@ -1292,7 +1290,7 @@ load(S, {ApplData, ApplEnv, IncApps, Descr, Id, Vsn, Apps}) ->
     {ok, NewS}.
 
 unload(AppName, S) ->
-    {ok, IncApps} = get_env(AppName, included_applications),
+    {ok, IncApps} = get_key(AppName, included_applications),
     del_env(AppName),
     ets:delete(ac_tab, {loaded, AppName}),
     foldl(fun(App, S1) ->
@@ -1583,13 +1581,9 @@ do_change_appl({ok, {ApplData, Env, IncApps, Descr, Id, Vsn, Apps}},
     CmdLineEnv = get_cmd_env(AppName),
     NewEnv2 = merge_app_env(NewEnv1, CmdLineEnv),
 
-    %% included_apps is made into an env parameter as well
-    NewEnv3 = keyreplaceadd(included_applications, 1, NewEnv2,
-			    {included_applications, IncApps}),
-
     %% Update ets table with new application env
     del_env(AppName),
-    add_env(AppName, NewEnv3),
+    add_env(AppName, NewEnv2),
 
     OldAppl#appl{appl_data=ApplData,
 		 descr=Descr,
diff --git a/lib/kernel/test/application_SUITE.erl b/lib/kernel/test/application_SUITE.erl
index c00fb44c46..988f26280f 100644
--- a/lib/kernel/test/application_SUITE.erl
+++ b/lib/kernel/test/application_SUITE.erl
@@ -1603,8 +1603,7 @@ get_key(Conf) when is_list(Conf) ->
     {ok, [{init, [kalle]}, {takeover, []}, {go, [sune]}]} =
 	rpc:call(Cp1, application, get_key, [appinc, start_phases]),
     {ok, Env} = rpc:call(Cp1, application, get_key, [appinc ,env]),
-    [{included_applications,[appinc1,appinc2]},
-	   {own2,val2},{own_env1,value1}] = lists:sort(Env),
+    [{own2,val2},{own_env1,value1}] = lists:sort(Env),
     {ok, []} = rpc:call(Cp1, application, get_key, [appinc, modules]),
     {ok, {application_starter, [ch_sup, {appinc, 41, 43}] }} = 
 	rpc:call(Cp1, application, get_key, [appinc, mod]),
@@ -1625,8 +1624,7 @@ get_key(Conf) when is_list(Conf) ->
 		{mod, {application_starter, [ch_sup, {appinc, 41, 43}] }}, 
 		{start_phases, [{init, [kalle]}, {takeover, []}, {go, [sune]}]}]} = 
 	rpc:call(Cp1, application, get_all_key, [appinc]),
-    [{included_applications,[appinc1,appinc2]},
-	   {own2,val2},{own_env1,value1}] = lists:sort(Env),
+    [{own2,val2},{own_env1,value1}] = lists:sort(Env),
 
     {ok, "Test of new app file, including appnew"} =
 	gen_server:call({global, {ch,41}}, {get_pid_key, description}),
@@ -1643,8 +1641,7 @@ get_key(Conf) when is_list(Conf) ->
     {ok, [{init, [kalle]}, {takeover, []}, {go, [sune]}]} =
 	gen_server:call({global, {ch,41}}, {get_pid_key, start_phases}),
     {ok, Env} = gen_server:call({global, {ch,41}}, {get_pid_key, env}),
-    [{included_applications,[appinc1,appinc2]},
-	   {own2,val2},{own_env1,value1}] = lists:sort(Env),
+    [{own2,val2},{own_env1,value1}] = lists:sort(Env),
     {ok, []} = 
 	gen_server:call({global, {ch,41}}, {get_pid_key, modules}),
     {ok, {application_starter, [ch_sup, {appinc, 41, 43}] }} = 
@@ -1671,8 +1668,7 @@ get_key(Conf) when is_list(Conf) ->
 		{mod, {application_starter, [ch_sup, {appinc, 41, 43}] }}, 
 		{start_phases, [{init, [kalle]}, {takeover, []}, {go, [sune]}]}]} = 
 	gen_server:call({global, {ch,41}}, get_pid_all_key),
-    [{included_applications,[appinc1,appinc2]},
-	   {own2,val2},{own_env1,value1}] = lists:sort(Env),
+    [{own2,val2},{own_env1,value1}] = lists:sort(Env),
     
     stop_node_nice(Cp1),
     ok.
-- 
2.16.3