Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs/race conditions in shell #1124

Merged
merged 1 commit into from
Mar 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/rebar_prv_shell.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,25 @@ kill_old_user() ->
%% 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!
exit(P, kill),
wait_for_port_death(1000, P),
OldUser.

wait_for_port_death(N, _) when N < 0 ->
%% This risks displaying a warning!
whatever;
wait_for_port_death(N, P) ->
case erlang:port_info(P) of
undefined ->
ok;
_ ->
timer:sleep(10),
wait_for_port_death(N-10, P)
end.

setup_new_shell() ->
%% terminate the current user supervision structure
ok = supervisor:terminate_child(kernel_sup, user),
%% terminate the current user supervision structure, if any
_ = 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)
Expand Down