Repository navigation
more: exit when the key tty hangs up - #15264
Franklin-Qi wants to merge 1 commit into
Conversation
|
clippy is sad on 4 jobs :) rustfmt is sad too :) |
| if stdout.is_terminal() { | ||
| stdout.queue(Show)?.queue(LeaveAlternateScreen)?; | ||
| terminal::disable_raw_mode()?; | ||
| let _ = stdout.queue(Show); |
There was a problem hiding this comment.
why ignore all errors now, even in the normal (non hangup) path?
| revents: 0, | ||
| }; | ||
| // POLLHUP/ERR appear in revents even when `events` is 0. | ||
| let n = unsafe { libc::poll(std::ptr::from_mut(&mut pfd), 1, 0) }; |
There was a problem hiding this comment.
unsafe without a // SAFETY: comment. could we use nix/rustix poll instead of adding libc?
| n >= 0 && (pfd.revents & (libc::POLLHUP | libc::POLLERR | libc::POLLNVAL)) != 0 | ||
| } | ||
|
|
||
| fd_hung_up(stdin().as_raw_fd()) || fd_hung_up(stdout().as_raw_fd()) |
There was a problem hiding this comment.
stdin is the data pipe with cat file | more, it will report POLLHUP as soon as cat exits and more will quit right away, no?
please check the tty more actually reads keys from, and add a test for the piped case
| let _ = reset_term(); | ||
| return Ok(()); | ||
| } | ||
| let Ok(ready) = event::poll(Duration::from_millis(100)) else { |
There was a problem hiding this comment.
this turns any poll/read error into a silent success, is it really what we want?
| ); | ||
|
|
||
| let output = Command::new("python3").arg("-c").arg(script).output(); | ||
| let Ok(output) = output else { |
There was a problem hiding this comment.
silently passing when python3 is missing isn't great. could it use the existing pty helpers instead of an inline python script?
| let (child, mut controller, output) = | ||
| run_more_with_pty(&["-n", "65535"], "test.txt", "line1\nline2\nline3\n"); | ||
| assert!(output.contains("line1")); | ||
| run_more_with_pty(&["-n", "65535"], "test.txt", "line1\nline2\nline3\n"); assert!(output.contains("line1")); |
There was a problem hiding this comment.
broken formatting + unrelated change, please run cargo fmt
967e9ae to
7c4117b
Compare
Detect hangup on the same fd crossterm uses for keys (stdin if it was a tty at startup, otherwise /dev/tty), without treating a closed content pipe as keyboard EOF. Avoid crossterm's timed poll busy-loop by using a zero-timeout poll plus a short sleep. Closes: uutils#15258
7c4117b to
734e47a
Compare
Merging this PR will regress 1 benchmark
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | factor_five_38_bit_primes |
1.9 s | 2.1 s | -10.78% |
| ⚡ | Simulation | factor_three_39_bit_primes |
598.6 ms | 473.9 ms | +26.3% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing Franklin-Qi:fix/15258-more-hangup-busy-loop (734e47a) with main (dccea81)2
Footnotes
-
70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
No successful run was found on
main(781b499) during the generation of this report, so dccea81 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
Enable crossterm use-dev-tty so EOF is not a tight mio read loop, and leave the event loop when stdin/stdout report POLLHUP.
Closes: #15258