Skip to content

Commit db261e8

Browse files
committed
kernel: prevent crash when calling io:getopts when user_drv is down
1 parent f1feb9e commit db261e8

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/kernel/src/group.erl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,13 @@ getopts(Data) ->
800800
true -> unicode;
801801
_ -> latin1
802802
end},
803-
Terminal = get_terminal_state(Data#state.driver),
804-
Tty = {terminal, maps:get(stdout, Terminal)},
805-
[Exp,Echo,LineHistory,Log,Bin,Uni,Tty|maps:to_list(Terminal)].
803+
case get_terminal_state(Data#state.driver) of
804+
Terminal when is_map(Terminal) ->
805+
Tty = {terminal, maps:get(stdout, Terminal)},
806+
[Exp,Echo,LineHistory,Log,Bin,Uni,Tty|maps:to_list(Terminal)];
807+
Error ->
808+
Error
809+
end.
806810

807811
%% Convert error code to make it look as before
808812
err_func(io_lib, get_until, {_,F,_}) ->

lib/stdlib/src/shell.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,11 @@ get_command(Prompt, Eval, Bs, RT, FT, Ds) ->
397397
Parse =
398398
fun() ->
399399
put('$ancestors', Ancestors),
400-
PreviousHistory = proplists:get_value(line_history, io:getopts()),
401-
[ok = io:setopts([{line_history, true}]) || PreviousHistory =/= undefined],
400+
PreviousHistory = case io:getopts() of
401+
{error,_} -> undefined;
402+
Opts0 -> proplists:get_value(line_history, Opts0)
403+
end,
404+
_ = [io:setopts([{line_history, true}]) || PreviousHistory =/= undefined],
402405
Res = io:scan_erl_exprs(group_leader(), Prompt, {1,1},
403406
[text,{reserved_word_fun,ResWordFun}]),
404407
_ = [io:setopts([{line_history, PreviousHistory}]) || PreviousHistory =/= undefined],

0 commit comments

Comments
 (0)