Skip to content

Commit 0f7d95e

Browse files
vtjnashKristofferC
authored andcommitted
remove workaround for controlling terminal behavior in repl_cmd (#58554)
This was originally added as a workaround for the behavior of sh to try to become the terminal process group leader, but no longer relevant since #25006 removed that flag again: ``` julia> run(detach(`bash -i -c "sleep 0"`)) bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell Process(`bash -i -c 'sleep 0'`, ProcessExited(0)) ``` Long explanation: Julia recieves SIGTTOU when a process like "sh -i -c" exits (at least for bash and zsh, but not dash, ksh, or csh), since "sh -i" sometimes takes over the controlling terminal, causing julia to stop once the bash process exits. This can be quite annoying, but julia goes through some pains (in libuv) to ensure it doesn't steal the controlling terminal from the parent, and apparently bash is not so careful about it. However, since PR #25006, julia hasn't needed this workaround for this issue, so we can now follow the intended behavior when the child is in the same session group and steals the controlling terminal from the parent. Even if such behavior seems odd, this seems to be the intended behavior per posix design implementation that it gets SIGTTOU when julia later tries to change mode (from cooked -> raw after printing the prompt): http://curiousthing.org/sigttin-sigttou-deep-dive-linux. For some background on why this is a useful signal and behavior and should not be just blocked, see nodejs/node#35536. According to glibc, there's a half page of code for how to correctly implement a REPL mode change call: https://www.gnu.org/software/libc/manual/html_node/Initializing-the-Shell.html ``` $ ./julia -q shell> bash -i -c "sleep 1" [1]+ Stopped ./julia julia> run(`zsh -i -c "sleep 0"`) Process(`zsh -i -c 'sleep 0'`, ProcessExited(0)) julia> [1]+ Stopped ./julia ``` (cherry picked from commit 0cbe466)
1 parent 7bea4c5 commit 0f7d95e

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

base/client.jl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ stackframe_lineinfo_color() = repl_color("JULIA_STACKFRAME_LINEINFO_COLOR", :bol
3232
stackframe_function_color() = repl_color("JULIA_STACKFRAME_FUNCTION_COLOR", :bold)
3333

3434
function repl_cmd(cmd, out)
35-
shell = shell_split(get(ENV, "JULIA_SHELL", get(ENV, "SHELL", "/bin/sh")))
36-
shell_name = Base.basename(shell[1])
37-
3835
# Immediately expand all arguments, so that typing e.g. ~/bin/foo works.
3936
cmd.exec .= expanduser.(cmd.exec)
4037

@@ -64,19 +61,15 @@ function repl_cmd(cmd, out)
6461
cd(dir)
6562
println(out, pwd())
6663
else
67-
@static if !Sys.iswindows()
68-
if shell_name == "fish"
69-
shell_escape_cmd = "begin; $(shell_escape_posixly(cmd)); and true; end"
70-
else
71-
shell_escape_cmd = "($(shell_escape_posixly(cmd))) && true"
72-
end
64+
if !Sys.iswindows()
65+
shell = shell_split(get(ENV, "JULIA_SHELL", get(ENV, "SHELL", "/bin/sh")))
66+
shell_escape_cmd = shell_escape_posixly(cmd)
7367
cmd = `$shell -c $shell_escape_cmd`
7468
end
7569
try
7670
run(ignorestatus(cmd))
7771
catch
78-
# Windows doesn't shell out right now (complex issue), so Julia tries to run the program itself
79-
# Julia throws an exception if it can't find the program, but the stack trace isn't useful
72+
# Julia throws an exception if it can't find the cmd (which may be the shell itself), but the stack trace isn't useful
8073
lasterr = current_exceptions()
8174
lasterr = ExceptionStack([(exception = e[1], backtrace = [] ) for e in lasterr])
8275
invokelatest(display_error, lasterr)

0 commit comments

Comments
 (0)