From 206bd1ced863f0757a2e15b74b533170460dd328 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Mon, 14 Apr 2025 22:20:44 +0200 Subject: [PATCH] Merge pull request #23268 from chrboesch/i19875 std.posix: Added 'error.ProcessNotFound' where necessary --- lib/std/fs.zig | 1 + lib/std/fs/Dir.zig | 7 +++++++ lib/std/fs/File.zig | 1 + lib/std/posix.zig | 22 ++++++++++++++-------- lib/std/zig/system.zig | 2 ++ 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index fc2da3de72..b33383dc2d 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -512,6 +512,7 @@ pub const SelfExePathError = error{ /// On Windows, `\\server` or `\\server\share` was not found. NetworkNotFound, + ProcessNotFound, /// On Windows, antivirus software is enabled by default. It can be /// disabled, but Windows Update sometimes ignores the user's preference diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index 8be324c0e8..d05ee03ef9 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -784,6 +784,7 @@ pub const OpenError = error{ DeviceBusy, /// On Windows, `\\server` or `\\server\share` was not found. NetworkNotFound, + ProcessNotFound, } || posix.UnexpectedError; pub fn close(self: *Dir) void { @@ -1696,6 +1697,7 @@ pub const DeleteDirError = error{ BadPathName, /// On Windows, `\\server` or `\\server\share` was not found. NetworkNotFound, + ProcessNotFound, Unexpected, }; @@ -2005,6 +2007,7 @@ pub const DeleteTreeError = error{ FileSystem, FileBusy, DeviceBusy, + ProcessNotFound, /// One of the path components was not a directory. /// This error is unreachable if `sub_path` does not contain a path separator. @@ -2079,6 +2082,7 @@ pub fn deleteTree(self: Dir, sub_path: []const u8) DeleteTreeError!void { error.PermissionDenied, error.SymLinkLoop, error.ProcessFdQuotaExceeded, + error.ProcessNotFound, error.NameTooLong, error.SystemFdQuotaExceeded, error.NoDevice, @@ -2175,6 +2179,7 @@ pub fn deleteTree(self: Dir, sub_path: []const u8) DeleteTreeError!void { error.AccessDenied, error.PermissionDenied, error.SymLinkLoop, + error.ProcessNotFound, error.ProcessFdQuotaExceeded, error.NameTooLong, error.SystemFdQuotaExceeded, @@ -2282,6 +2287,7 @@ fn deleteTreeMinStackSizeWithKindHint(self: Dir, sub_path: []const u8, kind_hint error.AccessDenied, error.PermissionDenied, error.SymLinkLoop, + error.ProcessNotFound, error.ProcessFdQuotaExceeded, error.NameTooLong, error.SystemFdQuotaExceeded, @@ -2383,6 +2389,7 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File error.PermissionDenied, error.SymLinkLoop, error.ProcessFdQuotaExceeded, + error.ProcessNotFound, error.NameTooLong, error.SystemFdQuotaExceeded, error.NoDevice, diff --git a/lib/std/fs/File.zig b/lib/std/fs/File.zig index 51745065f9..30b98cddf0 100644 --- a/lib/std/fs/File.zig +++ b/lib/std/fs/File.zig @@ -52,6 +52,7 @@ pub const OpenError = error{ Unexpected, /// On Windows, `\\server` or `\\server\share` was not found. NetworkNotFound, + ProcessNotFound, /// On Windows, antivirus software is enabled by default. It can be /// disabled, but Windows Update sometimes ignores the user's preference /// and re-enables it. When enabled, antivirus software on Windows diff --git a/lib/std/posix.zig b/lib/std/posix.zig index bc9e836c63..ad65cf205d 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -869,7 +869,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { .INTR => continue, .INVAL => unreachable, .FAULT => unreachable, - .NOENT => return error.ProcessNotFound, + .SRCH => return error.ProcessNotFound, .AGAIN => return error.WouldBlock, .CANCELED => return error.Canceled, .BADF => return error.NotOpenForReading, // Can be a race condition. @@ -933,7 +933,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize { .INTR => continue, .INVAL => unreachable, .FAULT => unreachable, - .NOENT => return error.ProcessNotFound, + .SRCH => return error.ProcessNotFound, .AGAIN => return error.WouldBlock, .BADF => return error.NotOpenForReading, // can be a race condition .IO => return error.InputOutput, @@ -1013,7 +1013,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { .INTR => continue, .INVAL => unreachable, .FAULT => unreachable, - .NOENT => return error.ProcessNotFound, + .SRCH => return error.ProcessNotFound, .AGAIN => return error.WouldBlock, .BADF => return error.NotOpenForReading, // Can be a race condition. .IO => return error.InputOutput, @@ -1155,7 +1155,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { .INTR => continue, .INVAL => unreachable, .FAULT => unreachable, - .NOENT => return error.ProcessNotFound, + .SRCH => return error.ProcessNotFound, .AGAIN => return error.WouldBlock, .BADF => return error.NotOpenForReading, // can be a race condition .IO => return error.InputOutput, @@ -1277,7 +1277,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { .INTR => continue, .INVAL => return error.InvalidArgument, .FAULT => unreachable, - .NOENT => return error.ProcessNotFound, + .SRCH => return error.ProcessNotFound, .AGAIN => return error.WouldBlock, .BADF => return error.NotOpenForWriting, // can be a race condition. .DESTADDRREQ => unreachable, // `connect` was never called. @@ -1353,7 +1353,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { .INTR => continue, .INVAL => return error.InvalidArgument, .FAULT => unreachable, - .NOENT => return error.ProcessNotFound, + .SRCH => return error.ProcessNotFound, .AGAIN => return error.WouldBlock, .BADF => return error.NotOpenForWriting, // Can be a race condition. .DESTADDRREQ => unreachable, // `connect` was never called. @@ -1443,7 +1443,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { .INTR => continue, .INVAL => return error.InvalidArgument, .FAULT => unreachable, - .NOENT => return error.ProcessNotFound, + .SRCH => return error.ProcessNotFound, .AGAIN => return error.WouldBlock, .BADF => return error.NotOpenForWriting, // Can be a race condition. .DESTADDRREQ => unreachable, // `connect` was never called. @@ -1528,7 +1528,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz .INTR => continue, .INVAL => return error.InvalidArgument, .FAULT => unreachable, - .NOENT => return error.ProcessNotFound, + .SRCH => return error.ProcessNotFound, .AGAIN => return error.WouldBlock, .BADF => return error.NotOpenForWriting, // Can be a race condition. .DESTADDRREQ => unreachable, // `connect` was never called. @@ -1607,6 +1607,9 @@ pub const OpenError = error{ /// On Windows, `\\server` or `\\server\share` was not found. NetworkNotFound, + /// This error occurs in Linux if the process to be open was not found. + ProcessNotFound, + /// One of these three things: /// * pathname refers to an executable image which is currently being /// executed and write access was requested. @@ -1666,6 +1669,7 @@ pub fn openZ(file_path: [*:0]const u8, flags: O, perm: mode_t) OpenError!fd_t { .NFILE => return error.SystemFdQuotaExceeded, .NODEV => return error.NoDevice, .NOENT => return error.FileNotFound, + .SRCH => return error.ProcessNotFound, .NOMEM => return error.SystemResources, .NOSPC => return error.NoSpaceLeft, .NOTDIR => return error.NotDir, @@ -1837,6 +1841,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: O, mode: mode_t) O .NFILE => return error.SystemFdQuotaExceeded, .NODEV => return error.NoDevice, .NOENT => return error.FileNotFound, + .SRCH => return error.ProcessNotFound, .NOMEM => return error.SystemResources, .NOSPC => return error.NoSpaceLeft, .NOTDIR => return error.NotDir, @@ -5483,6 +5488,7 @@ pub const RealPathError = error{ FileSystem, BadPathName, DeviceBusy, + ProcessNotFound, SharingViolation, PipeBusy, diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 5ddc3432f9..d58db11e12 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -843,6 +843,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion { error.NoDevice, => return error.GLibCNotFound, + error.ProcessNotFound, error.ProcessFdQuotaExceeded, error.SystemFdQuotaExceeded, error.SystemResources, @@ -886,6 +887,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion { error.FileTooBig => return error.Unexpected, + error.ProcessNotFound, error.ProcessFdQuotaExceeded, error.SystemFdQuotaExceeded, error.SystemResources,