From 7f82eddfaa3b89f734b4d58f1de92db86e5880cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 19 Oct 2010 13:43:13 +0200 Subject: Fix hang in on_load handlers in embedded mode In embedded mode, all on_load handlers will be called after loading all modules but before starting any servers. Therefore, if an on_load handler calls any function in the code module that calls the code server (such as code:priv_dir/1), there will be a deadlock because the code server has not yet been started. Fix this problem by invoking the on_load handlers after having started most servers in the kernel application. --- erts/preloaded/ebin/init.beam | Bin 44348 -> 44504 bytes erts/preloaded/src/init.erl | 41 +++++++++++---------- lib/kernel/src/kernel.erl | 7 ++++ .../on_load_app-1.0/src/on_load_embedded.erl | 9 +++++ 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/erts/preloaded/ebin/init.beam b/erts/preloaded/ebin/init.beam index f1b54b7fcb..f8af88b899 100644 Binary files a/erts/preloaded/ebin/init.beam and b/erts/preloaded/ebin/init.beam differ diff --git a/erts/preloaded/src/init.erl b/erts/preloaded/src/init.erl index 3b98b9cddc..255f33c299 100644 --- a/erts/preloaded/src/init.erl +++ b/erts/preloaded/src/init.erl @@ -51,6 +51,9 @@ get_status/0,boot/1,get_arguments/0,get_plain_arguments/0, get_argument/1,script_id/0]). +%% for the on_load functionality; not for general use +-export([run_on_load_handlers/0]). + %% internal exports -export([fetch_loaded/0,ensure_loaded/1,make_permanent/2, notify_when_started/1,wait_until_started/0, @@ -308,24 +311,6 @@ boot_loop(BootPid, State) -> {stop,Reason} -> stop(Reason,State); {From,fetch_loaded} -> %% Fetch and reset initially loaded modules. - case whereis(?ON_LOAD_HANDLER) of - undefined -> - %% There is no on_load handler process, - %% probably because init:restart/0 has been - %% called and it is not the first time we - %% pass through here. - ok; - Pid when is_pid(Pid) -> - Pid ! run_on_load, - receive - {'EXIT',Pid,on_load_done} -> - ok; - {'EXIT',Pid,Res} -> - %% Failure to run an on_load handler. - %% This is fatal during start-up. - exit(Res) - end - end, From ! {init,State#state.loaded}, garb_boot_loop(BootPid,State#state{loaded = []}); {From,{ensure_loaded,Module}} -> @@ -1335,9 +1320,27 @@ archive_extension() -> %%% Support for handling of on_load functions. %%% +run_on_load_handlers() -> + Ref = monitor(process, ?ON_LOAD_HANDLER), + catch ?ON_LOAD_HANDLER ! run_on_load, + receive + {'DOWN',Ref,process,_,noproc} -> + %% There is no on_load handler process, + %% probably because init:restart/0 has been + %% called and it is not the first time we + %% pass through here. + ok; + {'DOWN',Ref,process,_,on_load_done} -> + ok; + {'DOWN',Ref,process,_,Res} -> + %% Failure to run an on_load handler. + %% This is fatal during start-up. + exit(Res) + end. + start_on_load_handler_process() -> register(?ON_LOAD_HANDLER, - spawn_link(fun on_load_handler_init/0)). + spawn(fun on_load_handler_init/0)). on_load_handler_init() -> on_load_loop([]). diff --git a/lib/kernel/src/kernel.erl b/lib/kernel/src/kernel.erl index 92ee7b441a..d3b0f6c712 100644 --- a/lib/kernel/src/kernel.erl +++ b/lib/kernel/src/kernel.erl @@ -143,6 +143,13 @@ init(safe) -> Boot = start_boot_server(), DiskLog = start_disk_log(), Pg2 = start_pg2(), + + %% Run the on_load handlers for all modules that have been + %% loaded so far. Running them at this point means that + %% on_load handlers can safely call kernel processes + %% (and in particular call code:priv_dir/1 or code:lib_dir/1). + init:run_on_load_handlers(), + {ok, {SupFlags, Boot ++ DiskLog ++ Pg2}}. get_code_args() -> diff --git a/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl b/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl index a39332f81d..b7fdd4d9ae 100644 --- a/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl +++ b/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl @@ -3,6 +3,15 @@ -on_load(run_me/0). run_me() -> + %% An onload handler typically calls code:priv_dir/1 + %% or code:lib_dir/1, so make sure that it works. + LibDir = code:lib_dir(on_load_app), + PrivDir = code:priv_dir(on_load_app), + LibDir = filename:dirname(PrivDir), + ModPath = code:which(?MODULE), + LibDir = filename:dirname(filename:dirname(ModPath)), + + %% Start a process to remember that the on_load was called. spawn(fun() -> register(everything_is_fine, self()), receive Any -> -- cgit v1.2.3 From d20bbf4f3fe70ed3a00990b0ceb11292732318b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 20 Oct 2010 13:51:06 +0200 Subject: Teach -init_debug to print info about on_load handlers begin run --- erts/preloaded/ebin/init.beam | Bin 44504 -> 44856 bytes erts/preloaded/src/init.erl | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/erts/preloaded/ebin/init.beam b/erts/preloaded/ebin/init.beam index f8af88b899..c8d3b78b35 100644 Binary files a/erts/preloaded/ebin/init.beam and b/erts/preloaded/ebin/init.beam differ diff --git a/erts/preloaded/src/init.erl b/erts/preloaded/src/init.erl index 255f33c299..3ab9a1cd6d 100644 --- a/erts/preloaded/src/init.erl +++ b/erts/preloaded/src/init.erl @@ -721,6 +721,7 @@ do_boot(Init,Flags,Start) -> BootList = get_boot(BootFile,Root), LoadMode = b2a(get_flag('-mode',Flags,false)), Deb = b2a(get_flag('-init_debug',Flags,false)), + catch ?ON_LOAD_HANDLER ! {init_debug_flag,Deb}, BootVars = get_flag_args('-boot_var',Flags), ParallelLoad = (Pgm =:= "efile") and (erlang:system_info(thread_pool_size) > 0), @@ -1343,18 +1344,21 @@ start_on_load_handler_process() -> spawn(fun on_load_handler_init/0)). on_load_handler_init() -> - on_load_loop([]). + on_load_loop([], false). -on_load_loop(Mods) -> +on_load_loop(Mods, Debug0) -> receive + {init_debug_flag,Debug} -> + on_load_loop(Mods, Debug); {loaded,Mod} -> - on_load_loop([Mod|Mods]); + on_load_loop([Mod|Mods], Debug0); run_on_load -> - run_on_load_handlers(Mods), + run_on_load_handlers(Mods, Debug0), exit(on_load_done) end. -run_on_load_handlers([M|Ms]) -> +run_on_load_handlers([M|Ms], Debug) -> + debug(Debug, {running_on_load_handler,M}), Fun = fun() -> Res = erlang:call_on_load_function(M), exit(Res) @@ -1366,9 +1370,12 @@ run_on_load_handlers([M|Ms]) -> erlang:finish_after_on_load(M, Keep), case Keep of false -> - exit({on_load_function_failed,M}); + Error = {on_load_function_failed,M}, + debug(Debug, Error), + exit(Error); true -> - run_on_load_handlers(Ms) + debug(Debug, {on_load_handler_returned_ok,M}), + run_on_load_handlers(Ms, Debug) end end; -run_on_load_handlers([]) -> ok. +run_on_load_handlers([], _) -> ok. -- cgit v1.2.3 From 85ce3f39ba8e131d8b13ca5ade4836e703b4d041 Mon Sep 17 00:00:00 2001 From: Lars Thorsen Date: Fri, 1 Oct 2010 15:23:01 +0200 Subject: Fix that the documentation top index generator can handle an Ericsson internal application group --- system/doc/top/Makefile | 2 +- system/doc/top/src/erl_html_tools.erl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/system/doc/top/Makefile b/system/doc/top/Makefile index 148fefaf13..aac90fcaa4 100644 --- a/system/doc/top/Makefile +++ b/system/doc/top/Makefile @@ -246,7 +246,7 @@ release_docs_spec: docs $(INSTALL_DATA) $(INDEX_FILES) $(MAN_INDEX) $(TOP_HTML_FILES) $(RELSYSDIR) $(INSTALL_DIR) $(RELSYSDIR)/docbuild $(INSTALL_DATA) $(INDEX_SCRIPT) $(MAN_INDEX_SCRIPT) $(JAVASCRIPT_BUILD_SCRIPT) \ - $(INDEX_SCRIPT_SRC) $(MAN_INDEX_SCRIPT_SRC) $(JAVASCRIPT_BUILD_SCRIPT_SRC) \ + $(INDEX_SRC) $(MAN_INDEX_SRC) $(JAVASCRIPT_BUILD_SCRIPT_SRC) \ $(TEMPLATES) $(RELSYSDIR)/docbuild diff --git a/system/doc/top/src/erl_html_tools.erl b/system/doc/top/src/erl_html_tools.erl index fef56331fc..599268804e 100644 --- a/system/doc/top/src/erl_html_tools.erl +++ b/system/doc/top/src/erl_html_tools.erl @@ -40,7 +40,8 @@ group_order() -> {test, "Test"}, {doc, "Documentation"}, {orb, "Object Request Broker & IDL"}, - {misc, "Miscellaneous"} + {misc, "Miscellaneous"}, + {eric, "Ericsson Internal"} ]. top_index() -> -- cgit v1.2.3 From 1419cda9991775c51a931ef63a51da477391722c Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Thu, 21 Oct 2010 12:09:29 +0200 Subject: Prepare release --- erts/doc/src/notes.xml | 29 +++++++++++++++++++++++++++++ erts/vsn.mk | 2 +- lib/kernel/doc/src/notes.xml | 23 +++++++++++++++++++++++ lib/kernel/vsn.mk | 2 +- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/erts/doc/src/notes.xml b/erts/doc/src/notes.xml index 532ebc29e2..1703ce0942 100644 --- a/erts/doc/src/notes.xml +++ b/erts/doc/src/notes.xml @@ -30,6 +30,35 @@

This document describes the changes made to the ERTS application.

+
Erts 5.8.1.2 + +
Fixed Bugs and Malfunctions + + +

Fix that the documentation top index generator can + handle an Ericsson internal application group.

+

+ Own Id: OTP-8875

+
+ +

In embedded mode, on_load handlers that called + code:priv_dir/1 or other functions in code + would hang the system. Since the crypto + application now contains an on_loader handler that calls + code:priv_dir/1, including the crypto + application in the boot file would prevent the system + from starting.

+

Also extended the -init_debug option to print + information about on_load handlers being run to + facilitate debugging.

+

+ Own Id: OTP-8902 Aux Id: seq11703

+
+
+
+ +
+
Erts 5.8.1.1
Fixed Bugs and Malfunctions diff --git a/erts/vsn.mk b/erts/vsn.mk index af9744f012..9f1f1e1998 100644 --- a/erts/vsn.mk +++ b/erts/vsn.mk @@ -17,7 +17,7 @@ # %CopyrightEnd% # -VSN = 5.8.1.1 +VSN = 5.8.1.2 SYSTEM_VSN = R14B # Port number 4365 in 4.2 diff --git a/lib/kernel/doc/src/notes.xml b/lib/kernel/doc/src/notes.xml index 9859183390..edd6ea52b0 100644 --- a/lib/kernel/doc/src/notes.xml +++ b/lib/kernel/doc/src/notes.xml @@ -30,6 +30,29 @@

This document describes the changes made to the Kernel application.

+
Kernel 2.14.1.1 + +
Fixed Bugs and Malfunctions + + +

In embedded mode, on_load handlers that called + code:priv_dir/1 or other functions in code + would hang the system. Since the crypto + application now contains an on_loader handler that calls + code:priv_dir/1, including the crypto + application in the boot file would prevent the system + from starting.

+

Also extended the -init_debug option to print + information about on_load handlers being run to + facilitate debugging.

+

+ Own Id: OTP-8902 Aux Id: seq11703

+
+
+
+ +
+
Kernel 2.14.1
Fixed Bugs and Malfunctions diff --git a/lib/kernel/vsn.mk b/lib/kernel/vsn.mk index 651d082379..802e326f7c 100644 --- a/lib/kernel/vsn.mk +++ b/lib/kernel/vsn.mk @@ -1 +1 @@ -KERNEL_VSN = 2.14.1 +KERNEL_VSN = 2.14.1.1 -- cgit v1.2.3