Explorar el Código

Correct TTY type detection

This reuses the trick used within OTP to pick within old and new shell.

The 'user' structure is the same for all cases (escript, escript + dumb
TERM, unstable install, unstable install + dumb TERM), so we take it
down first.

Then we boot the TTY driver, which fails if TERM=dumb, in which case we
boot the retro-style usr. If it worked, we shut down the driver again,
and boot a modern shell structure.

This avoids all warnings and seems to work in all cases.
pull/995/head
Fred Hebert hace 9 años
padre
commit
f704707335
Se han modificado 1 ficheros con 23 adiciones y 17 borrados
  1. +23
    -17
      src/rebar_prv_shell.erl

+ 23
- 17
src/rebar_prv_shell.erl Ver fichero

@ -112,36 +112,42 @@ info() ->
"Start a shell with project and deps preloaded similar to~n'erl -pa ebin -pa deps/*/ebin'.~n".
setup_shell() ->
case process_info(whereis(user), current_function) of
{_,{user,_,_}} -> setup_old_shell();
_ -> setup_new_shell()
end.
OldUser = kill_old_user(),
%% Test for support here
NewUser = try erlang:open_port({spawn,'tty_sl -c -e'}, []) of
Port when is_port(Port) ->
true = port_close(Port),
setup_new_shell()
catch
error:_ ->
setup_old_shell()
end,
rewrite_leaders(OldUser, NewUser).
setup_new_shell() ->
%% scan all processes for any with references to the old user and save them to
%% update later
kill_old_user() ->
OldUser = whereis(user),
%% terminate the current user
%% terminate the current user's port, in a way that makes it shut down,
%% but without taking down the supervision tree so that the escript doesn't
%% fully die
[P] = [P || P <- element(2,process_info(whereis(user), links)), is_port(P)],
user ! {'EXIT', P, normal}, % pretend the port died, then the port can die!
OldUser.
setup_new_shell() ->
%% terminate the current user supervision structure
ok = supervisor:terminate_child(kernel_sup, user),
%% start a new shell (this also starts a new user under the correct group)
_ = user_drv:start(),
%% wait until user_drv and user have been registered (max 3 seconds)
ok = wait_until_user_started(3000),
NewUser = whereis(user),
rewrite_leaders(OldUser, NewUser).
whereis(user).
setup_old_shell() ->
%% scan all processes for any with references to the old user and save them to
%% update later
OldUser = whereis(user),
%% terminate the current user's port, in a way that makes it shut down,
%% but without taking down the supervision tree so that the escript doesn't
%% fully die
[P] = [P || P <- element(2,process_info(whereis(user), links)), is_port(P)],
user ! {'EXIT', P, normal}, % pretend the port died, then the port can die!
NewUser = rebar_user:start(), % hikack IO stuff with fake user
NewUser = whereis(user),
rewrite_leaders(OldUser, NewUser).
NewUser.
rewrite_leaders(OldUser, NewUser) ->
%% set any process that had a reference to the old user's group leader to the

Cargando…
Cancelar
Guardar