Skip to content

remove workaround for controlling terminal behavior in repl_cmd #58554

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

Merged
merged 1 commit into from
May 29, 2025

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented May 28, 2025

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))

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.

$ ./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

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))
```

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.

```
$ ./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
```
@vtjnash vtjnash added REPL Julia's REPL (Read Eval Print Loop) backport 1.12 Change should be backported to release-1.12 labels May 28, 2025
@vtjnash
Copy link
Member Author

vtjnash commented May 29, 2025

For background on why this is a useful signal and behavior and should not be just blocked, see nodejs/node#35536

@vtjnash
Copy link
Member Author

vtjnash commented May 29, 2025

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

@vtjnash vtjnash merged commit 0cbe466 into master May 29, 2025
7 of 10 checks passed
@vtjnash vtjnash deleted the jn/repl_cmd_session branch May 29, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.12 Change should be backported to release-1.12 REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant