- if !HAS_STATX.load(Ordering::Relaxed) {
- return None;
- }
-
- let mut buf: libc::statx = mem::zeroed();
- let ret = cvt(statx(fd, path, flags, mask, &mut buf));
- match ret {
- Err(err) => match err.raw_os_error() {
- Some(libc::ENOSYS) => {
- HAS_STATX.store(false, Ordering::Relaxed);
- return None;
+ match STATX_STATE.load(Ordering::Relaxed) {
+ // For the first time, we try to call on current working directory
+ // to check if it is available.
+ 0 => {
+ let mut buf: libc::statx = mem::zeroed();
+ let err = cvt(statx(
+ libc::AT_FDCWD,
+ b".\0".as_ptr().cast(),
+ 0,
+ libc::STATX_ALL,
+ &mut buf,
+ ))
+ .err()
+ .and_then(|e| e.raw_os_error());
+ // `seccomp` will emit `EPERM` on denied syscall.
+ // See: https://github.com/rust-lang/rust/issues/65662
+ if err == Some(libc::ENOSYS) || err == Some(libc::EPERM) {
+ STATX_STATE.store(1, Ordering::Relaxed);
+ } else {
+ STATX_STATE.store(2, Ordering::Relaxed);