Skip to content

Commit 38f6165

Browse files
authored
Rollup merge of #106661 - mjguzik:linux_statx, r=Mark-Simulacrum
Stop probing for statx unless necessary As is the current toy program: fn main() -> std::io::Result<()> { use std::fs; let metadata = fs::metadata("foo.txt")?; assert!(!metadata.is_dir()); Ok(()) } ... observed under strace will issue: [snip] statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address) statx(AT_FDCWD, "foo.txt", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0 While statx is not necessarily always present, checking for it can be delayed to the first error condition. Said condition may very well never happen, in which case the check got avoided altogether. Note this is still suboptimal as there still will be programs issuing it, but bulk of the problem is removed. Tested by forbidding the syscall for the binary and observing it correctly falls back to newfstatat. While here tidy up the commentary, in particular by denoting some problems with the current approach.
2 parents 932c5a0 + be87fb1 commit 38f6165

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tests/pass-dep/shims/libc-fs-with-isolation.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ fn main() {
2222
}
2323

2424
// test `stat`
25-
assert_eq!(fs::metadata("foo.txt").unwrap_err().kind(), ErrorKind::PermissionDenied);
25+
let err = fs::metadata("foo.txt").unwrap_err();
26+
assert_eq!(err.kind(), ErrorKind::PermissionDenied);
2627
// check that it is the right kind of `PermissionDenied`
27-
assert_eq!(Error::last_os_error().raw_os_error(), Some(libc::EACCES));
28+
assert_eq!(err.raw_os_error(), Some(libc::EACCES));
2829
}

0 commit comments

Comments
 (0)