Skip to content

tail: fix following redirected stdin - #9093

Open
mattsu2020 wants to merge 1 commit into
uutils:mainfrom
mattsu2020:tail_f_fix
Open

mattsu2020 wants to merge 1 commit into
uutils:mainfrom
mattsu2020:tail_f_fix

Conversation

@mattsu2020

@mattsu2020 mattsu2020 commented Oct 30, 2025 •

Copy link
Copy Markdown
Contributor

tail -f < file exits after the initial read instead of following further appends. Resolve and watch redirected stdin at read time and reuse its open descriptor, preserving the input offset and following the same file after renames, replacements, or truncation.

Add regression coverage for redirected stdin and descriptor following, with unsupported cases skipped on WASI.

Closes #7614

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@anastygnome

Copy link
Copy Markdown
Contributor

The CI fail seems unrelated.

Could you squash your commits, for us to review your work better, and prepare for the future merge?

@github-actions

github-actions Bot commented Nov 1, 2025

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@mattsu2020

Copy link
Copy Markdown
Contributor Author

The CI fail seems unrelated.

Could you squash your commits, for us to review your work better, and prepare for the future merge?

Done

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

1 similar comment
@github-actions

github-actions Bot commented Dec 1, 2025

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tail/follow-name is no longer failing!

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/follow-name (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cut/bounded-memory is now being skipped but was previously passing.
Note: The gnu test tests/dd/no-allocate is now being skipped but was previously passing.
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Congrats! The gnu test tests/tail/pipe-f is now passing!

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/date/date-locale-hour. tests/date/date-locale-hour is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/follow-name (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/misc/io-errors is no longer failing!
Note: The gnu test tests/printf/printf-surprise is now being skipped but was previously passing.
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.

Comment thread src/uu/tail/src/follow/watch.rs Resolved
Comment thread src/uu/tail/src/follow/watch.rs Resolved
Comment thread src/uu/tail/src/follow/watch.rs Resolved
Comment thread src/uu/tail/src/tail.rs Resolved
Comment thread src/uu/tail/src/tail.rs Outdated
return Ok(());
}

if path.metadata().map(|meta| meta.is_dir()).unwrap_or(false) {

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.

tail_file already handles directories, this duplicates it. could we just let it go there?

Comment thread src/uu/tail/src/tail.rs Resolved
Comment thread tests/by-util/test_tail.rs Resolved
@mattsu2020
mattsu2020 marked this pull request as draft October 8, 2026 13:00
@mattsu2020
mattsu2020 marked this pull request as ready for review October 9, 2026 11:15
Comment thread src/uu/tail/src/follow/mod.rs Outdated
}

#[allow(clippy::unnecessary_wraps)]
pub fn set_stdin_key<P: Into<PathBuf>>(&mut self, _path: P) -> UResult<()> {

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.

i am really not a fan of this function.
it probably demonstrates a refactor

@mattsu2020
mattsu2020 marked this pull request as draft October 10, 2026 11:26
@codspeed

codspeed Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will regress 1 benchmark

⚠️ This run is associated to a commit that was force-pushed

It won't be associated with its branch history. Be careful when comparing its performance to other runs.

⚠️ 69 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

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
❌ 1 regressed benchmark
✅ 119 untouched benchmarks
⏩ 333 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ three_39_bit_primes 591.3 ms 774.5 ms -23.65%
⚡ five_38_bit_primes 2.1 s 1.8 s +18.77%
⚡ thirteen_39_bit_primes 9.6 s 8.6 s +12.12%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing mattsu2020:tail_f_fix (4ebd4de) with main (01a8fc0)

Open in CodSpeed

Footnotes

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

@mattsu2020 mattsu2020 changed the title Fix: tail -f test fails tail: fix following redirected stdin Oct 10, 2026
@mattsu2020
mattsu2020 marked this pull request as ready for review November 14, 2026 12:11
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/usage_vs_getopt (passes in this run but fails in the 'main' branch)

@anastygnome

Copy link
Copy Markdown
Contributor

You need to annotate the test not to run on wasi

Comment thread src/uu/tail/src/tail.rs Resolved
Comment thread src/uu/tail/src/chunks.rs Resolved
Comment thread src/uu/tail/src/follow/watch.rs Outdated
let mut paths: Vec<PathBuf> = vec![];
let display_name = self.files.get(event_path).display_name.clone();

if self.follow_descriptor()

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 early return skips the whole match below for -f. could it go into the existing arms instead of adding a parallel path?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed it

Comment thread src/uu/tail/src/follow/watch.rs Outdated

// With -f, sleep for approximately N seconds (default 1.0) between iterations;
// We wake up if Notify sends an Event or if we wait more than `sleep_sec`.
let wait = if !observer.use_polling

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.

do we really need a second timer next to timeout_counter? this is getting hard to follow

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed it

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for picking this up!
But it is a large PR :(

This does more than fix tail -f < file: please split the offset fixes into another PR (see inline) and get CI green on wasm and macOS.
Then please squash into one commit.

@sylvestre

Copy link
Copy Markdown
Contributor

sorry but it needs to be rebased, and a bunch of jobs are failing

@mattsu2020
mattsu2020 marked this pull request as draft November 15, 2026 14:53
@mattsu2020
mattsu2020 marked this pull request as ready for review November 16, 2026 11:15

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.

tail: -f option doesn't work with stdin

3 participants