Skip to content

rm: overriding the libc call when implementation does not match gnu coreutils exactly - #9604

Closed
ChrisDryden wants to merge 7 commits into
uutils:mainfrom
ChrisDryden:example_ld_fix
Closed

ChrisDryden wants to merge 7 commits into
uutils:mainfrom
ChrisDryden:example_ld_fix

Conversation

@ChrisDryden

@ChrisDryden ChrisDryden commented Dec 8, 2025 •

Copy link
Copy Markdown
Collaborator

This was originally intended to be a demonstration for how we could modify the integration tests to recognize the libc calls we were using.

I discovered that I could wrap the implementation in this helper method to be able to address this tests in a relatively readable way compared to modifying the original code.

As it stands I believe there are three skipped tests in total right now that are skipped for this reason

@github-actions

github-actions Bot commented Dec 8, 2025

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/rm/rm-readdir-fail is now passing!

1 similar comment
@github-actions

github-actions Bot commented Dec 8, 2025

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/rm/rm-readdir-fail is now passing!

@ChrisDryden ChrisDryden changed the title rm: example of how to override the glibc call when implementation does not match gnu coreutils exactly rm: overriding the libc call when implementation does not match gnu coreutils exactly Dec 8, 2025
@ChrisDryden
ChrisDryden marked this pull request as ready for review December 9, 2025 02:36
@sylvestre

Copy link
Copy Markdown
Contributor

sorry, it needs to be rebased

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/rm/rm-readdir-fail is now passing!

Comment thread util/build-gnu.sh
@@ -5,6 +5,7 @@
# spell-checker:ignore (paths) abmon deref discrim eacces getlimits getopt ginstall inacc infloop inotify reflink ; (misc) INT_OFLOW OFLOW
# spell-checker:ignore baddecode submodules xstrtol distros ; (vars/env) SRCDIR vdir rcexp xpart dired OSTYPE ; (utils) greadlink gsed multihardlink texinfo CARGOFLAGS
# spell-checker:ignore openat TOCTOU CFLAGS tmpfs gnproc
# spell-checker:ignore hfsplus casefold chattr dirp memcpy

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.

Is hfsplus really used?

@sylvestre

Copy link
Copy Markdown
Contributor

need to be rebased

Comment thread util/build-gnu.sh
# * the selinux crate is handling errors
# * the test says "maybe we should not fail when no context available"
sed -i -e "s|returns_ 1||g" tests/cp/no-ctx.sh
"${SED}" -i -e "s|returns_ 1||g" tests/cp/no-ctx.sh

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.

We have

command -v gsed && sed(){ gsed "$@";}
SED=$(command -v gsed||command -v sed) # for find...exec...

@codspeed

codspeed Bot commented Jan 20, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 12.07%

⚡ 4 improved benchmarks
✅ 319 untouched benchmarks
⏩ 46 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Simulation tsort_tree_dag[(10, 3)] 29.1 ms 25.3 ms +15.16%
⚡ Simulation tsort_wide_dag[100000] 115.9 ms 102.4 ms +13.23%
⚡ Simulation tsort_linear_chain[1000000] 1.4 s 1.3 s +10.34%
⚡ Simulation tsort_complex_dag[50000] 73.2 ms 66.8 ms +9.65%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ChrisDryden:example_ld_fix (34e78f0) with main (073b882)2

Open in CodSpeed

Footnotes

  1. 46 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 (844a21a) during the generation of this report, so 073b882 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/rm/rm-readdir-fail is now passing!

@github-actions

github-actions Bot commented Feb 9, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/rm/rm-readdir-fail is now passing!
Congrats! The gnu test tests/tail/tail-n0f is now passing!

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/follow-name (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/rm/rm-readdir-fail is now passing!

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.
Congrats! The gnu test tests/cp/link-heap is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!
Note: The gnu test tests/env/env-signal-handler was skipped on 'main' but is now failing.

@oech3

This comment was marked as resolved.

@sylvestre

Copy link
Copy Markdown
Contributor

sorry but it needs to be rebased

};

// Check if readdir failed partway through (partial read)
if let Some(err) = take_errno() {

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 is probably what makes clippy fail (collapsible_if), please use if let ... && ...

};

// Check if readdir failed partway through (partial read)
if let Some(err) = take_errno() {

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.

please add a test in tests/by-util/test_rm.rs too

}

/// Clear errno and return any error that was set after an operation
/// This is used because the nix library does not propagate folder reading errors correctly

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.

is that true? dir.iter() already yields Err and we propagate it with ? just below


/// Clear errno and return any error that was set after an operation
/// This is used because the nix library does not propagate folder reading errors correctly
pub fn take_errno() -> Option<io::Error> {

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.

relying on errno after a successful call is fragile: dup/closedir/malloc can leave it set even when read_dir succeeded.
could read_dir_entries return the partial entries + the error instead?

Comment thread util/build-gnu.sh
"${SED}" -i -e "s|returns_ 1||g" tests/cp/no-ctx.sh

# uutils rm uses nix which calls readdir64_r, so add a wrapper that delegates to the readdir hook
"${SED}" -i '/^struct dirent \*readdir/i\

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.

injecting C into the GNU test with sed is hard to maintain, could this be a quilt patch in util/gnu-patches/ instead?

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.

It seems readdir64_r is unrecommended syscall. We should ask nix to stop using that instead of patching the test.

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.

But backend syscall might be changed after this PR was submitted since this PR is old.
We need to re-investigate reason for failure of tests/rm/rm-readdir-fail now.

@oech3

oech3 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

This PR can be closed as dd39af2 was merged.

@sylvestre

Copy link
Copy Markdown
Contributor

sorry but it needs to be rebased

@sylvestre sylvestre closed this Nov 10, 2026
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.

3 participants