aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/code_server.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2014-05-09 12:35:22 +0200
committerBjörn Gustavsson <[email protected]>2014-06-04 16:43:17 +0200
commited06dd12ea74018b902a2c4c7924313d23cedb75 (patch)
tree4d4ac5c25f19119d447182984d1cfb8e03aff245 /lib/kernel/src/code_server.erl
parent32f33d9897261b15573e7e606d990e60e294fc22 (diff)
downloadotp-ed06dd12ea74018b902a2c4c7924313d23cedb75.tar.gz
otp-ed06dd12ea74018b902a2c4c7924313d23cedb75.tar.bz2
otp-ed06dd12ea74018b902a2c4c7924313d23cedb75.zip
Make pre-loaded modules permanently sticky
Modules in the kernel, stdlib, and compiler applications are by default "sticky", meaning that the code server will refuse to re-load them. The pre-loaded modules (those that are part of the run-time system itself, such as 'erlang') are, however, not sticky. They used to be sticky a long time ago when the pre-loaded modules were part of the kernel application. Now they are part of the erts application. Since re-loading a pre-loaded module can be catastrophic (especially re-loading the 'erlang' module), the pre-loaded modules must be sticky. Furthermore, it should not be allowed to unstick them. The sticky_dir/1 test case in code_SUITE is never actually run and is broken. Rewrite it.
Diffstat (limited to 'lib/kernel/src/code_server.erl')
-rw-r--r--lib/kernel/src/code_server.erl16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/kernel/src/code_server.erl b/lib/kernel/src/code_server.erl
index f891cb61c4..dd06affd70 100644
--- a/lib/kernel/src/code_server.erl
+++ b/lib/kernel/src/code_server.erl
@@ -63,7 +63,10 @@ init(Ref, Parent, [Root,Mode0]) ->
process_flag(trap_exit, true),
Db = ets:new(code, [private]),
- foreach(fun (M) -> ets:insert(Db, {M,preloaded}) end, erlang:pre_loaded()),
+ foreach(fun (M) ->
+ %% Pre-loaded modules are always sticky.
+ ets:insert(Db, [{M,preloaded},{{sticky,M},true}])
+ end, erlang:pre_loaded()),
ets:insert(Db, init:fetch_loaded()),
Mode =
@@ -1165,7 +1168,7 @@ stick_dir(Dir, Stick, St) ->
true ->
foreach(fun (M) -> ets:insert(Db, {{sticky,M},true}) end, Mods);
false ->
- foreach(fun (M) -> ets:delete(Db, {sticky,M}) end, Mods)
+ foreach(fun (M) -> do_unstick_mod(Db, M) end, Mods)
end;
Error ->
Error
@@ -1177,6 +1180,15 @@ stick_mod(M, Stick, St) ->
true ->
ets:insert(Db, {{sticky,M},true});
false ->
+ do_unstick_mod(Db, M)
+ end.
+
+do_unstick_mod(Db, M) ->
+ case ets:lookup(Db, M) of
+ [{M,preloaded}] ->
+ %% Never unstick pre-loaded modules.
+ true;
+ _ ->
ets:delete(Db, {sticky,M})
end.