| author | |
| committer | |
| log | b773a8b175b6be130af2249f267e4113fdbf30ea |
| tree | 0ae3b738d90819fc06bc4cad579c9e4d89638aa1 |
| parent | 4532f5ecad23a3478310f159f43d31217c863c35 |
3 files changed, 20 insertions(+), 12 deletions(-)
lib/std/fs.zig+1-1| ... | @@ -1605,7 +1605,7 @@ pub fn readLinkC(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | ... | @@ -1605,7 +1605,7 @@ pub fn readLinkC(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 1605 | return os.readlinkC(pathname_c, buffer); | 1605 | return os.readlinkC(pathname_c, buffer); |
| 1606 | } | 1606 | } |
| 1607 | 1607 | ||
| 1608 | pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfExePathError; | 1608 | pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfExePathError || os.FcntlError; |
| 1609 | 1609 | ||
| 1610 | pub fn openSelfExe() OpenSelfExeError!File { | 1610 | pub fn openSelfExe() OpenSelfExeError!File { |
| 1611 | if (builtin.os.tag == .linux) { | 1611 | if (builtin.os.tag == .linux) { |
lib/std/fs/file.zig+1-1| ... | @@ -34,7 +34,7 @@ pub const File = struct { | ... | @@ -34,7 +34,7 @@ pub const File = struct { |
| 34 | else => 0o666, | 34 | else => 0o666, |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | pub const OpenError = windows.CreateFileError || os.OpenError; | 37 | pub const OpenError = windows.CreateFileError || os.OpenError || os.FcntlError; |
| 38 | 38 | ||
| 39 | /// TODO https://github.com/ziglang/zig/issues/3802 | 39 | /// TODO https://github.com/ziglang/zig/issues/3802 |
| 40 | pub const OpenFlags = struct { | 40 | pub const OpenFlags = struct { |
lib/std/os.zig+18-10| ... | @@ -1146,18 +1146,26 @@ pub const LockCmd = enum { | ... | @@ -1146,18 +1146,26 @@ pub const LockCmd = enum { |
| 1146 | SetLockBlocking, | 1146 | SetLockBlocking, |
| 1147 | }; | 1147 | }; |
| 1148 | 1148 | ||
| 1149 | pub const FcntlError = error{ | ||
| 1150 | /// The file is locked by another process | ||
| 1151 | FileLocked, | ||
| 1152 | } || UnexpectedError; | ||
| 1153 | |||
| 1149 | /// Attempts to get lock the file, blocking if the file is locked. | 1154 | /// Attempts to get lock the file, blocking if the file is locked. |
| 1150 | pub fn fcntlFlock(fd: fd_t, lock_cmd: LockCmd, flock_p: *Flock) OpenError!void { | 1155 | pub fn fcntlFlock(fd: fd_t, lock_cmd: LockCmd, flock_p: *Flock) FcntlError!void { |
| 1151 | const cmd: i32 = cmdval: { | 1156 | const cmd: i32 = switch (lock_cmd) { |
| 1152 | switch (lock_cmd) { | 1157 | .GetLock => F_GETLK, |
| 1153 | .GetLock => break :cmdval F_GETLK, | 1158 | .SetLock => F_SETLK, |
| 1154 | .SetLock => break :cmdval F_SETLK, | 1159 | .SetLockBlocking => F_SETLKW, |
| 1155 | .SetLockBlocking => break :cmdval F_SETLKW, | ||
| 1156 | } | ||
| 1157 | }; | 1160 | }; |
| 1158 | const rc = system.fcntl(fd, cmd, flock_p); | 1161 | while (true) { |
| 1159 | if (rc < 0) { | 1162 | switch (errno(system.fcntl(fd, cmd, flock_p))) { |
| 1160 | std.debug.panic("fcntl error: {}\n", .{rc}); | 1163 | 0 => return, |
| 1164 | EACCES => return error.FileLocked, | ||
| 1165 | EAGAIN => return error.FileLocked, | ||
| 1166 | EINTR => continue, | ||
| 1167 | else => |err| return unexpectedErrno(err), | ||
| 1168 | } | ||
| 1161 | } | 1169 | } |
| 1162 | } | 1170 | } |
| 1163 | 1171 |