mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
std: fix inappropriate use of unreachable in fanotify_init
This commit is contained in:
parent
4ceefca14b
commit
4442288656
@ -516,7 +516,7 @@ const Os = switch (builtin.os.tag) {
|
||||
pub fn init() !Watch {
|
||||
switch (builtin.os.tag) {
|
||||
.linux => {
|
||||
const fan_fd = try std.posix.fanotify_init(.{
|
||||
const fan_fd = std.posix.fanotify_init(.{
|
||||
.CLASS = .NOTIF,
|
||||
.CLOEXEC = true,
|
||||
.NONBLOCK = true,
|
||||
@ -524,7 +524,10 @@ pub fn init() !Watch {
|
||||
.REPORT_DIR_FID = true,
|
||||
.REPORT_FID = true,
|
||||
.REPORT_TARGET_FID = true,
|
||||
}, 0);
|
||||
}, 0) catch |err| switch (err) {
|
||||
error.UnsupportedFlags => fatal("fanotify_init failed due to old kernel; requires 5.17+", .{}),
|
||||
else => |e| return e,
|
||||
};
|
||||
return .{
|
||||
.dir_table = .{},
|
||||
.os = switch (builtin.os.tag) {
|
||||
|
||||
@ -4544,13 +4544,16 @@ pub const FanotifyInitError = error{
|
||||
SystemFdQuotaExceeded,
|
||||
SystemResources,
|
||||
PermissionDenied,
|
||||
/// The kernel does not recognize the flags passed, likely because it is an
|
||||
/// older version.
|
||||
UnsupportedFlags,
|
||||
} || UnexpectedError;
|
||||
|
||||
pub fn fanotify_init(flags: std.os.linux.fanotify.InitFlags, event_f_flags: u32) FanotifyInitError!i32 {
|
||||
const rc = system.fanotify_init(flags, event_f_flags);
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return @intCast(rc),
|
||||
.INVAL => unreachable,
|
||||
.INVAL => return error.UnsupportedFlags,
|
||||
.MFILE => return error.ProcessFdQuotaExceeded,
|
||||
.NFILE => return error.SystemFdQuotaExceeded,
|
||||
.NOMEM => return error.SystemResources,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user