Skip to content

Commit

Permalink
erts: Fix so that prim_tty can be reloaded
Browse files Browse the repository at this point in the history
This is needed for when prim_tty is cover compiled.
  • Loading branch information
garazdawi committed Aug 29, 2022
1 parent 759f609 commit 919561f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
18 changes: 9 additions & 9 deletions erts/emulator/nifs/common/prim_tty_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,7 @@ static void tty_select_stop(ErlNifEnv* caller_env, void* obj, ErlNifEvent event,
#endif
}

static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
{

static void load_resources(ErlNifEnv* env, ErlNifResourceFlags rt_flags) {
ErlNifResourceTypeInit rt = {
NULL /* dtor */,
tty_select_stop,
Expand All @@ -1008,10 +1006,13 @@ static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
ATOMS
#undef ATOM_DECL

*priv_data = NULL;

tty_rt = enif_open_resource_type_x(env, "tty", &rt, ERL_NIF_RT_CREATE, NULL);
tty_rt = enif_open_resource_type_x(env, "tty", &rt, rt_flags, NULL);
}

static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
{
*priv_data = NULL;
load_resources(env, ERL_NIF_RT_CREATE);
return 0;
}

Expand All @@ -1029,8 +1030,7 @@ static int upgrade(ErlNifEnv* env, void** priv_data, void** old_priv_data,
if (*priv_data != NULL) {
return -1; /* Don't know how to do that */
}
if (load(env, priv_data, load_info)) {
return -1;
}
*priv_data = NULL;
load_resources(env, ERL_NIF_RT_TAKEOVER);
return 0;
}
3 changes: 1 addition & 2 deletions lib/kernel/src/prim_tty.erl
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@
%% proc_lib exports
-export([reader/1, writer/1]).

-export([on_load/0]).

-on_load(on_load/0).

%%-define(debug, true).
-ifdef(debug).
Expand Down
1 change: 0 additions & 1 deletion lib/kernel/src/user_drv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ callback_mode() -> state_functions.
-spec init(arguments()) -> gen_statem:init_result(init).
init(Args) ->
process_flag(trap_exit, true),
prim_tty:on_load(),
IsTTY = prim_tty:isatty(stdin) =:= true andalso prim_tty:isatty(stdout) =:= true,
StartShell = maps:get(initial_shell, Args, undefined) =/= noshell,
try
Expand Down

0 comments on commit 919561f

Please sign in to comment.