Skip to content

tail: honor _POSIX2_VERSION for bare -c and +NUM obsolete forms - #15529

Open
emirmrkaljevic wants to merge 2 commits into
uutils:mainfrom
emirmrkaljevic:tail-c-missing-count
Open

emirmrkaljevic wants to merge 2 commits into
uutils:mainfrom
emirmrkaljevic:tail-c-missing-count

Conversation

@emirmrkaljevic

Copy link
Copy Markdown
Contributor

Summary

  • A bare tail -c (no count) was read as the obsolete form and printed the last 10 bytes. GNU only does that under POSIX 1992 (_POSIX2_VERSION below 200112); otherwise -c needs a value. Now -c alone falls back to the normal "a value is required" error unless _POSIX2_VERSION selects POSIX 1992.
  • POSIX 2001 has no +NUM form, so with _POSIX2_VERSION in 200112..200809 an argument like +2 is now a file name, as in GNU. The default and 200809/199209 keep reading +NUM as before.

Both checks use the existing uucore::posix helpers (like sort and uniq) and sit in parse_obsolete, before the obsolete parser runs.

$ printf 'abcdefghijkl' | ./target/debug/tail -c
error: a value is required for '--bytes <[+]NUM>' but none was supplied
$ printf 'abcdefghijkl' | _POSIX2_VERSION=199209 ./target/debug/tail -c
cdefghijkl
$ printf 'a\nb\n' | _POSIX2_VERSION=200112 ./target/debug/tail +2
tail: cannot open '+2' for reading: No such file or directory

Fixes #15528

Test plan

  • New test_tail_obsolete_bare_c_needs_posix_1992 and test_tail_obsolete_plus_is_a_file_under_posix_2001; both fail without the change
  • cargo test --no-default-features --features tail test_tail::: 174 passed, 12 ignored; cargo test -p uu_tail --lib: 38 passed
  • cargo fmt --check, cargo clippy -p uu_tail --all-targets -- -D warnings
  • stdout and exit codes match GNU coreutils 9.12 for -c, -b, -l, -, +, +c, +5, -5c, +3c, +2 FILE, -c 3, -n 2 with no _POSIX2_VERSION and with 199209, 200112 and 200809 (only -c 3 under 199209 differs, see the issue)

Found with behave.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

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

Comment thread src/uu/tail/src/args.rs
use uucore::parser::parse_size::ParseSizeError;
use uucore::parser::parse_time;
use uucore::parser::shortcut_value_parser::ShortcutValueParser;
use uucore::posix::{MODERN, TRADITIONAL, posix_version};

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.

could you please also drop tail (TBD) from the list in src/uucore/src/lib/mods/posix.rs? :)

Comment thread src/uu/tail/src/args.rs
}

pub fn parse_obsolete(arg: &OsString, input: Option<&OsString>) -> UResult<Option<Settings>> {
let posix = posix_version();

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.

did you run the GNU tail tests too? tail.pl has a few _POSIX2_VERSION cases
setup: git clone https://github.com/coreutils/coreutils.git ../gnu
run: bash util/build-gnu.sh && bash util/run-gnu-test.sh tests/tail/tail.pl

@emirmrkaljevic

Copy link
Copy Markdown
Contributor Author

Thanks! I removed the "(TBD)" marker for tail in posix.rs. tail now uses the posix module, so I kept it listed like uniq. Happy to drop the line completely if you'd prefer that. I also ran the GNU tail tests: tests/tail/tail.pl passes, including the _POSIX2_VERSION cases (PASS: 1, FAIL: 0).

@codspeed

codspeed Bot commented Oct 20, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 15.86%

⚠️ 119 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.

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

❌ 1 regressed benchmark
✅ 400 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation true_consecutive_calls 294.7 ns 350.2 ns -15.86%

Tip

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


Comparing emirmrkaljevic:tail-c-missing-count (319958a) with main (5fda18e)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 (b77b664) during the generation of this report, so 5fda18e 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.

tail: bare -c and +NUM obsolete forms ignore _POSIX2_VERSION

2 participants