diff options
author | Richard Carlsson <[email protected]> | 2015-12-01 11:25:12 +0100 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2016-05-20 18:39:23 +0200 |
commit | be353901879b3cccda7cd01947936cf1550dea04 (patch) | |
tree | de27e9109f893f84915e5b304f2d67792cf31c54 /erts/preloaded | |
parent | f1be30c44044e7bb0167a34d234b6b2322328def (diff) | |
download | otp-be353901879b3cccda7cd01947936cf1550dea04.tar.gz otp-be353901879b3cccda7cd01947936cf1550dea04.tar.bz2 otp-be353901879b3cccda7cd01947936cf1550dea04.zip |
Check exit status in init:stop/1 and simplify documentation
Diffstat (limited to 'erts/preloaded')
-rw-r--r-- | erts/preloaded/src/init.erl | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/erts/preloaded/src/init.erl b/erts/preloaded/src/init.erl index 618b53f6bb..04c5210aa3 100644 --- a/erts/preloaded/src/init.erl +++ b/erts/preloaded/src/init.erl @@ -90,6 +90,8 @@ -define(ON_LOAD_HANDLER, init__boot__on_load_handler). +-define(MAX_HALT_STRING_SIZE, 199). + debug(false, _) -> ok; debug(_, T) -> erlang:display(T). @@ -173,7 +175,25 @@ stop() -> init ! {stop,stop}, ok. -spec stop(Status) -> 'ok' when Status :: non_neg_integer() | string(). -stop(Status) -> init ! {stop,{stop,Status}}, ok. +stop(Status) when is_integer(Status), Status >= 0 -> + stop_1(Status); +stop(Status) when is_list(Status) -> + case is_bytelist(Status) of + true -> + stop_1(limit_halt_string(Status)); + false -> + erlang:error(badarg) + end; +stop(_) -> + erlang:error(badarg). + +is_bytelist([B|Bs]) when is_integer(B), B >= 0, B < 256 -> is_bytelist(Bs); +is_bytelist([]) -> true; +is_bytelist(_) -> false. + +%% Note that we check the type of Status beforehand to ensure that +%% the call to halt(Status) by the init process cannot fail +stop_1(Status) -> init ! {stop,{stop,Status}}, ok. -spec boot(BootArgs) -> no_return() when BootArgs :: [binary()]. @@ -285,16 +305,12 @@ things_to_string([]) -> "". halt_string(String, List) -> - HaltString = String ++ things_to_string(List), - if - length(HaltString)<199 -> HaltString; - true -> first198(HaltString, 198) - end. + limit_halt_string(String ++ things_to_string(List)). -first198([H|T], N) when N>0 -> - [H|first198(T, N-1)]; -first198(_, 0) -> - []. +limit_halt_string(String) when length(String) < ?MAX_HALT_STRING_SIZE -> + String; +limit_halt_string(String) -> + lists:sublist(String, ?MAX_HALT_STRING_SIZE-1). %% String = string() %% List = [string() | atom() | pid() | number()] |