-
-
Notifications
You must be signed in to change notification settings - Fork 3k
std.posix.faccessat
: fallback to older faccessat
syscall if possible
#24900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5054,7 +5054,22 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces | |
} else if (native_os == .wasi and !builtin.link_libc) { | ||
return faccessat(dirfd, mem.sliceTo(path, 0), mode, flags); | ||
} | ||
switch (errno(system.faccessat(dirfd, path, mode, flags))) { | ||
|
||
const flags_unsupported = switch (system) { | ||
linux => (builtin.abi.isAndroid() //standard android programs run in a seccomp sandbox that seems to trigger signal 31 (SIGSYS) for faccessat2 | ||
or builtin.target.os.isAtLeast(.linux, .{ .major = 5, .minor = 8, .patch = 0 }) != true), //faccessat2 was introduced in Linux 5.8 | ||
else => false, | ||
}; | ||
const need_flags = (flags != 0); | ||
if (need_flags and flags_unsupported) return error.UnsupportedFlags; | ||
const faccessat_result = switch (system) { | ||
linux => if (need_flags) //the older, simpler syscall should stay supported, so we only need to use faccessat2 if we need flags | ||
linux.faccessat2(dirfd, path, mode, flags) | ||
else | ||
linux.faccessat(dirfd, path, mode), | ||
else => system.faccessat(dirfd, path, mode, flags), | ||
}; | ||
switch (errno(faccessat_result)) { | ||
.SUCCESS => return, | ||
.ACCES => return error.AccessDenied, | ||
.PERM => return error.PermissionDenied, | ||
|
@@ -5072,6 +5087,10 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces | |
return error.InvalidUtf8 | ||
else | ||
return unexpectedErrno(err), | ||
.NOSYS => |err| if (system == linux) | ||
return error.UnsupportedFlags | ||
Comment on lines
+5090
to
+5091
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under what conditions are we expecting to hit this branch? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Building for a non-android target range including no support (expected before Linux kernel 5.8) and support (expected Linux kernel 5.8 and later), There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked at |
||
else | ||
return unexpectedErrno(err), | ||
else => |err| return unexpectedErrno(err), | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I forgot to check whether
error.UnsupportedFlags
is in the error set, and it's not.I took it from the
FanotifyInitError
error set, because the description seemed to pretty much match the situation here.Should we add
error.UnsupportedFlags
to theAccessError
error set, or is one of the other errors close enough to be used here?(On android it's basically a low-level permissions issue, so maybe
error.PermissionDenied
, but I kind of don't think users care about that technicality.)