Repository navigation
Foreground process group management, again - #6584
Conversation
|
Hi, thank you very much for your PR. Relative regions are something I'm not good at and it leaves some weird errors. Really appreciate the pr to make it better. |
|
Oh I see the current problem now: We really have to reuse the pgrp of the first external command in a pipeline like all the classic shells do, no way around that… |
5b567be to
9d3e723
Compare
|
Okay. Finally I think it might be correct! At least I'm not seeing any bugs right now. 🎉 It's really difficult to fit this running-pipeline-local state into the core of nushell, which kinda just doesn't want to be a unix shell actually >_< What I settled on was putting the state in Currently this is not the most beautiful code (the bare pair of atomics is a bit ugly and the trickery with the zero value is not very rust-y) but before polishing we need more testing! Please throw your best test cases at this! Go nuts with pipelines, try to break it! |
e2e6029 to
148d0c5
Compare
|
Hi @unrelentingtech, thanks a lot for working on this. My initial tests look good w.r.t piping commands that were previously broken in MacOS (e.g. However, I'm finding that it no longer works as the shell for tmux. To reproduce that, create a and then run to the screen, and dumping a log file named |
|
Similarly I'm finding that it exits immediately when set as the program for alacritty to run, i.e. in alacritty.yml (I'm using MacOS) |
|
I see, it's |
|
I confirm that on MacOS this branch results in tmux showing "python" in its status bar when I run python, and that that does not happen on nushell main. (My understanding (see #6542) is that that is the functional difference we expect between main and this branch.) |
…s while running external command (nushell#6273)" (nushell#6542)" This reverts commit 2bb367f.
These changes are mostly inspired by the glibc manual.
|
Reworked terminal acquirement code to do basically what fish does 🚀 @dandavison terminal title is a minor benefit of it. |
Excellent! Confirm works my end under tmux/alacritty.
Haha, yes, I absolutely believe that you that there are more profound benefits of this change than the terminal title! You've probably already thought about this -- and I am not suggesting that this block merging this PR -- but given the history of subtle bugs and slightly broken releases I think it would be really valuable to put in place some tests that verify aspects of correct process and signal handling, etc. I.e. tests that would fail on main now, and pass on this branch. I'm imagining that those would have to be a new style of "integration" test that involves building nu in CI, and running the built binary (I think those don't exist currently?). Do you agree that that would be valuable in principle and would you be able to make some suggestions for what sorts of tests and assertions might be feasible? It's not the easiest area to test but I think it would be great to protect your work against any future mistakes. |
|
I really don't have the energy for working on this kind of thing currently :/ but it's probably possible to do something similar to what fish does with pexpect testing. Ideally it would run various pipelines composed of an external test helper program controllable via a side channel, and check who's in the foreground at various points. |
That sounds like a great suggestion and looks like very helpful prior art from fish. I've opened |
|
wow, good work here. these are some pretty significant changes. |
|
One data point: I've been running a nushell build including these commits for the last week and haven't encountered any problems. |
|
I didn't realize this was ready for review? Is the work complete here? |
It will help to have lots of manual testing of this branch, from users with different workflows. I believe the branch is already in a state where manual testing from users is helpful. Quoting @unrelentingtech from above :)
|
|
Since we have a release tomorrow, I propose to wait a couple days and land it. That will give us about 3 weeks to test more thoroughly once it's merged. |
|
Hi @rosshadden , sorry for disturb Can you please verify if this patch works for #6156 |
|
Yep @WindSoilder this branch seems to work for me. |
|
@unrelentingtech if we can get this conflict resolved we can land it. |
|
Here we go, hold your breath and cross your fingers! |
| }; | ||
|
|
||
| let shell_pgid = unistd::getpgrp(); | ||
| let owner_pgid = unistd::tcgetpgrp(nix::libc::STDIN_FILENO).expect("tcgetpgrp"); |
There was a problem hiding this comment.
I am running into a new problem with this change:
Trying to launch interactive nushell via the CodeLLDB VS Code extension causes a panic on this line.
It appears that fd 0 is a valid tty and the atty crate is reporting the same thing. I don't fully grasp how we can deal with the other error cases vaguely described in https://man7.org/linux/man-pages/man3/tcgetpgrp.3.html
Reproducibility notes: both on Ubuntu standalone and with WSL2 I was able to cause this crash (for the external and internal terminal option in the launch.json config).
Launching gdb target/debug/nu was not picking up this panic if I get this correctly (but my gdb foo is not strong enough to properly launch nu in a separate terminal while being attached from the start.) Regular late attaching with gdb -p <nu pid> was not causing unexpected problems.
There was a problem hiding this comment.
hm, does fish work in the same place?
There was a problem hiding this comment.
Will have to read up on the launch configuration options for that.
There was a problem hiding this comment.
I opened a separate issue #6788 for that problem, even if fish were to crash there we shouldn't to enable us to debug other things on startup.
|
Sometimes my tests failed with the following message in the latest main: |
…9693) # Description Fixes a regression from #9681 where nushell will attempt to place itself into the background or take control of the terminal even in non-interactive mode. Using the same [reference](https://www.gnu.org/software/libc/manual/html_node/Initializing-the-Shell.html) from #6584: >A subshell that runs *interactively* has to ensure that it has been placed in the foreground... >A subshell that runs *non-interactively* cannot and should not support job control. `fish` [code](https://github.com/fish-shell/fish-shell/blob/54fa1ad6ec7adb0d9c14076843ef5e51c18ecc7a/src/reader.cpp#L4862) also seems to follow this. This *partially* fixes [9026](#9026). That is, nushell will no longer set the foreground process group in non-interactive mode.


Description
Continuing: #6273 #6240 #6156 #3861
This changes #6273 to work a lot more like what this manual describes.
As a result, I'm not getting the pipe hang bug which I could reproduce with
fd . . | fzy.There's still some kind of pipe bug though:fd . . | sksometimes works, sometimesthread 'main' panicked at 'failed to get next char from input',(with some other message blinking quickly).fd . . | fzfjust saysFailed to read /dev/tty.(probably just the fact that we're looking at stdin. when stdin is the piped input. we should explicitly carry the tty into the
pre_exec?)In addition… since for now there's no background support I've left
SIGTSTPignored in the spawned child process, so now the habit of Ctrl+Z'ing TUI applications won't cause an irrecoverable frozen mess (unless the application resets signal handling, but most don't. (quick testing: in htop, ncdu, helix, kakoune Ctrl-Z is ignored now; neovim hides its UI but it's possible to Ctrl-C it and not lose the shell)Tests
Make sure you've done the following:
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo test --workspace --features=extrato check that all the tests pass