Skip to content

Commit 3673849

Browse files
author
José Valim
committed
Use System.no_halt/1 instead of Process.sleep/1 in mix run
Otherwise :init.get_status will stay in {:starting, :started} forever.
1 parent 966d221 commit 3673849

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

lib/elixir/lib/kernel/cli.ex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Kernel.CLI do
55
commands: [],
66
output: ".",
77
compile: [],
8-
halt: true,
8+
no_halt: false,
99
compiler_options: [],
1010
errors: [],
1111
pa: [],
@@ -21,6 +21,7 @@ defmodule Kernel.CLI do
2121

2222
{config, argv} = parse_argv(argv)
2323
System.argv(argv)
24+
System.no_halt(config.no_halt)
2425

2526
fun = fn _ ->
2627
errors = process_commands(config)
@@ -31,7 +32,7 @@ defmodule Kernel.CLI do
3132
end
3233
end
3334

34-
run(fun, config.halt)
35+
run(fun)
3536
end
3637

3738
@doc """
@@ -42,10 +43,10 @@ defmodule Kernel.CLI do
4243
This function is used by Elixir's CLI and also
4344
by escripts generated by Elixir.
4445
"""
45-
def run(fun, halt \\ true) do
46+
def run(fun) do
4647
{ok_or_shutdown, status} = exec_fun(fun, {:ok, 0})
4748

48-
if ok_or_shutdown == :shutdown or halt do
49+
if ok_or_shutdown == :shutdown or not System.no_halt() do
4950
{_, status} = at_exit({ok_or_shutdown, status})
5051

5152
# Ensure Logger messages are flushed before halting
@@ -240,7 +241,7 @@ defmodule Kernel.CLI do
240241
end
241242

242243
defp parse_shared(["--no-halt" | t], config) do
243-
parse_shared(t, %{config | halt: false})
244+
parse_shared(t, %{config | no_halt: true})
244245
end
245246

246247
defp parse_shared(["-e", h | t], config) do

lib/elixir/lib/system.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,22 @@ defmodule System do
255255
:elixir_config.put(:argv, args)
256256
end
257257

258+
@doc """
259+
Marks if the system should halt or not at the end of ARGV processing.
260+
"""
261+
@spec no_halt(boolean) :: :ok
262+
def no_halt(boolean) when is_boolean(boolean) do
263+
:elixir_config.put(:no_halt, boolean)
264+
end
265+
266+
@doc """
267+
Checks if the system will halt or not at the end of ARGV processing.
268+
"""
269+
@spec no_halt() :: boolean
270+
def no_halt() do
271+
:elixir_config.get(:no_halt)
272+
end
273+
258274
@doc """
259275
Current working directory.
260276

lib/elixir/src/elixir.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ start(_Type, _Args) ->
6363
{bootstrap, false},
6464
{compiler_options, CompilerOpts},
6565
{home, unicode:characters_to_binary(Home, Encoding, Encoding)},
66-
{identifier_tokenizer, Tokenizer}
66+
{identifier_tokenizer, Tokenizer},
67+
{no_halt, false}
6768
| URIConfig
6869
],
6970

lib/mix/lib/mix/tasks/escript.build.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ defmodule Mix.Tasks.Escript.Build do
382382
]
383383

384384
io_error(error_message)
385-
386385
:erlang.halt(1)
387386
end
388387

@@ -391,7 +390,7 @@ defmodule Mix.Tasks.Escript.Build do
391390
load_config(@config)
392391
start_app(@app)
393392
args = Enum.map(args, &List.to_string(&1))
394-
Kernel.CLI.run(fn _ -> @module.main(args) end, true)
393+
Kernel.CLI.run(fn _ -> @module.main(args) end)
395394

396395
error ->
397396
io_error(["Failed to start Elixir.\n", :io_lib.format('error: ~p~n', [error])])

lib/mix/lib/mix/tasks/run.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ defmodule Mix.Tasks.Run do
8484
)
8585

8686
run(args, opts, head, &Code.eval_string/1, &Code.require_file/1)
87-
unless Keyword.get(opts, :halt, true), do: Process.sleep(:infinity)
87+
unless Keyword.get(opts, :halt, true), do: System.no_halt(true)
8888
Mix.Task.reenable("run")
8989
:ok
9090
end

0 commit comments

Comments
 (0)