authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-09-25 09:54:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-09-25 16:07:04-07:00
log44422886561f5c0029f3d61898609220bd35deea
tree7cd6dadebd1c3a5f881dae35d655644c55eeb4ee
parent4ceefca14be313e91a248fdc532e37edf4a02a51

std: fix inappropriate use of unreachable in fanotify_init


2 files changed, 9 insertions(+), 3 deletions(-)

lib/std/Build/Watch.zig+5-2
......@@ -516,7 +516,7 @@ const Os = switch (builtin.os.tag) {
516516pub fn init() !Watch {
517517 switch (builtin.os.tag) {
518518 .linux => {
519 const fan_fd = try std.posix.fanotify_init(.{
519 const fan_fd = std.posix.fanotify_init(.{
520520 .CLASS = .NOTIF,
521521 .CLOEXEC = true,
522522 .NONBLOCK = true,
......@@ -524,7 +524,10 @@ pub fn init() !Watch {
524524 .REPORT_DIR_FID = true,
525525 .REPORT_FID = true,
526526 .REPORT_TARGET_FID = true,
527 }, 0);
527 }, 0) catch |err| switch (err) {
528 error.UnsupportedFlags => fatal("fanotify_init failed due to old kernel; requires 5.17+", .{}),
529 else => |e| return e,
530 };
528531 return .{
529532 .dir_table = .{},
530533 .os = switch (builtin.os.tag) {
lib/std/posix.zig+4-1
......@@ -4544,13 +4544,16 @@ pub const FanotifyInitError = error{
45444544 SystemFdQuotaExceeded,
45454545 SystemResources,
45464546 PermissionDenied,
4547 /// The kernel does not recognize the flags passed, likely because it is an
4548 /// older version.
4549 UnsupportedFlags,
45474550} || UnexpectedError;
45484551
45494552pub fn fanotify_init(flags: std.os.linux.fanotify.InitFlags, event_f_flags: u32) FanotifyInitError!i32 {
45504553 const rc = system.fanotify_init(flags, event_f_flags);
45514554 switch (errno(rc)) {
45524555 .SUCCESS => return @intCast(rc),
4553 .INVAL => unreachable,
4556 .INVAL => return error.UnsupportedFlags,
45544557 .MFILE => return error.ProcessFdQuotaExceeded,
45554558 .NFILE => return error.SystemFdQuotaExceeded,
45564559 .NOMEM => return error.SystemResources,