Skip to content

df: replace unsafe libc sync with nix crate#11279

Open
mattsu2020 wants to merge 3 commits intouutils:mainfrom
mattsu2020:df_sync
Open

df: replace unsafe libc sync with nix crate#11279
mattsu2020 wants to merge 3 commits intouutils:mainfrom
mattsu2020:df_sync

Conversation

@mattsu2020
Copy link
Contributor

@mattsu2020 mattsu2020 commented Mar 10, 2026

Summary

df currently uses an unsafe libc::sync() call for --sync, with a separate Android-specific syscall(SYS_sync) branch.

This PR replaces that code with nix::unistd::sync(). That removes the manual libc/syscall handling and keeps the implementation simpler.

Changes

  • replace the unsafe sync call in src/uu/df/src/df.rs
  • remove the Android-specific SYS_sync branch
  • add nix as a Unix-only dependency for uu_df

Testing

  • cargo check -p uu_df
  • cargo test -p uu_df

Replace the unsafe libc sync call with the nix crate's sync_filesystems function for safer filesystem synchronization. This change improves code safety by using a well-maintained Rust wrapper instead of direct unsafe libc calls.
@mattsu2020 mattsu2020 changed the title refactor(df): replace unsafe libc sync with nix crate df: replace unsafe libc sync with nix crate Mar 10, 2026
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/rm/isatty is no longer failing!
Congrats! The gnu test tests/tail/retry is no longer failing!

@xtqqczze
Copy link
Contributor

libc added sync support for android in v0.2.142 (rust-lang/libc@0ba1fc4), so this should be fine.

Co-authored-by: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/expand/bounded-memory is now being skipped but was previously passing.
Congrats! The gnu test tests/cut/cut-huge-range is now passing!

Co-authored-by: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/expand/bounded-memory is now being skipped but was previously passing.
Note: The gnu test tests/pr/bounded-memory is now being skipped but was previously passing.
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.
Congrats! The gnu test tests/cut/cut-huge-range is now passing!

Copy link
Contributor

@xtqqczze xtqqczze left a comment

Choose a reason for hiding this comment

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

still not a fan of AI descriptions

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.

2 participants