Skip to content

more: exit when the key tty hangs up - #15264

Open
Franklin-Qi wants to merge 1 commit into
uutils:mainfrom
Franklin-Qi:fix/15258-more-hangup-busy-loop
Open

Franklin-Qi wants to merge 1 commit into
uutils:mainfrom
Franklin-Qi:fix/15258-more-hangup-busy-loop

Conversation

@Franklin-Qi

Copy link
Copy Markdown
Contributor

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

@sylvestre

Copy link
Copy Markdown
Contributor

clippy is sad on 4 jobs :)

rustfmt is sad too :)
could you please run cargo fmt?

Diff in /home/runner/work/coreutils/coreutils/tests/by-util/test_more.rs:330:
     // When -n is u16::MAX (65535), adding 1 for the banner line used to
     // overflow. Verify that more starts and displays content without crashing.
     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"));
     quit_more(&mut controller, child);
 }

##[endgroup]
     Removed 0 files
##[endgroup]
##[error]ssh exited with code 1
Post job cleanup.
[command]/usr/bin/git version
git version 2.55.0
Temporarily overriding HOME='/home/runner/work/_temp/a051b0d1-aa2a-4dd8-abf1-87cc508d6e57' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
[command]/usr/bin/git config --global --add safe.directory /home/runner/work/coreutils/coreutils

Comment thread src/uu/more/Cargo.toml Outdated
Comment thread src/uu/more/src/more.rs Outdated
Comment thread src/uu/more/src/more.rs Outdated
if stdout.is_terminal() {
stdout.queue(Show)?.queue(LeaveAlternateScreen)?;
terminal::disable_raw_mode()?;
let _ = stdout.queue(Show);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ignore all errors now, even in the normal (non hangup) path?

Comment thread src/uu/more/src/more.rs Outdated
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) };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsafe without a // SAFETY: comment. could we use nix/rustix poll instead of adding libc?

Comment thread src/uu/more/src/more.rs Outdated
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())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/uu/more/src/more.rs Outdated
let _ = reset_term();
return Ok(());
}
let Ok(ready) = event::poll(Duration::from_millis(100)) else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this turns any poll/read error into a silent success, is it really what we want?

Comment thread tests/by-util/test_more.rs Outdated
);

let output = Command::new("python3").arg("-c").arg(script).output();
let Ok(output) = output else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

silently passing when python3 is missing isn't great. could it use the existing pty helpers instead of an inline python script?

Comment thread tests/by-util/test_more.rs Outdated
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"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broken formatting + unrelated change, please run cargo fmt

@Franklin-Qi
Franklin-Qi force-pushed the fix/15258-more-hangup-busy-loop branch 2 times, most recently from 967e9ae to 7c4117b Compare October 16, 2026 09:14
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
@Franklin-Qi
Franklin-Qi force-pushed the fix/15258-more-hangup-busy-loop branch from 7c4117b to 734e47a Compare October 16, 2026 09:15
@codspeed

codspeed Bot commented Oct 16, 2026

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

⚠️ 118 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 399 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

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

Open in CodSpeed

Footnotes

  1. 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. ↩

  2. 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. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

more: busy-loops when its terminal hangs up

2 participants