Skip to content

perms: use rustix for ownership changes - #15509

Open
limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/perms-use-rustix-chown-12041
Open

limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/perms-use-rustix-chown-12041

Conversation

@limadog9

Copy link
Copy Markdown
Contributor

Replace libc chown/lchown with rustix chownat on supported targets. Preserve symlink handling and unchanged-ID sentinels, and return an error for NUL-containing paths.

Closes #12041.

@oech3

This comment was marked as outdated.

chownat(CWD, path.as_ref(), owner, group, flags).map_err(Into::into)
}

/// Redox does not provide rustix::fs::chownat.

@xtqqczze xtqqczze Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

add a TODO comment to remove once https://github.com/bytecodealliance/rustix/pull/1638 is released with rustix::fs::chownat

See bytecodealliance/rustix#1638.

@limadog9
limadog9 force-pushed the fix/perms-use-rustix-chown-12041 branch from 8c75df4 to 353b123 Compare October 18, 2026 20:37
@xtqqczze

Copy link
Copy Markdown
Collaborator

It seems rustix is missing lchown. That should probably be reported upstream.

Comment thread src/uucore/src/lib/features/perms.rs Outdated
use tempfile::tempdir;

#[test]
fn test_chown_symlinks_and_unchanged_ids() {

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 PR is refactoring only. Would you remove this? We already have tests for real binaries.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The PR changes an implementation, I think it is more than a refactoring.

@oech3 oech3 Oct 18, 2026 •

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 should use tests/by-util/* instead in any cases.

@limadog9
limadog9 force-pushed the fix/perms-use-rustix-chown-12041 branch from 353b123 to 410428a Compare October 18, 2026 20:49
@oech3

oech3 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Can we use rustix's chown (not at) at redox?

Comment thread src/uucore/src/lib/features/perms.rs Outdated
AtFlags::SYMLINK_NOFOLLOW
};
// -1 is the chown(2) sentinel meaning that the corresponding ID is unchanged.
let owner = (uid != uid_t::MAX).then(|| Uid::from_raw(uid));

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 need these two lines? Uid::from_raw(u32::MAX) is already -1 for the kernel

Comment thread src/uucore/src/lib/features/perms.rs Outdated
#[cfg(target_os = "redox")]
fn chown<P: AsRef<Path>>(path: P, uid: uid_t, gid: gid_t, follow: bool) -> IOResult<()> {
let path = path.as_ref();
let s = CString::new(path.as_os_str().as_bytes()).unwrap();

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.

the description says NUL paths now return an error, but this unwrap() is still there on redox, could you please map it to an error too?

@limadog9
limadog9 force-pushed the fix/perms-use-rustix-chown-12041 branch from 410428a to 7d5168d Compare October 18, 2026 22:27
Comment thread src/uucore/src/lib/features/perms.rs Outdated
fn chown<P: AsRef<Path>>(path: P, uid: uid_t, gid: gid_t, follow: bool) -> IOResult<()> {
let path = path.as_ref();
if follow {
let owner = (uid != uid_t::MAX).then(|| rustix::fs::Uid::from_raw(uid));

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.

same owner/group mapping as in the other chown, could be a small shared helper, no?

Replace libc chown/lchown with rustix chownat on supported targets. Preserve symlink handling and unchanged-ID sentinels, and return an error for NUL-containing paths.

Closes uutils#12041.
@limadog9
limadog9 force-pushed the fix/perms-use-rustix-chown-12041 branch from 7d5168d to d4c3e8e Compare October 19, 2026 19:35
@codspeed

codspeed Bot commented Oct 19, 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.

❌ 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 limadog9:fix/perms-use-rustix-chown-12041 (d4c3e8e) with main (6f60c70)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 (48f2a33) during the generation of this report, so 6f60c70 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.

Some unsafe chown(at) code can be removed by rustix

4 participants