Skip to content

std.posix: Added 'error.ProcessNotFound' where necessary #23268

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

Merged
merged 17 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/std/fs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/std/fs/Dir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1696,6 +1697,7 @@ pub const DeleteDirError = error{
BadPathName,
/// On Windows, `\\server` or `\\server\share` was not found.
NetworkNotFound,
ProcessNotFound,
Unexpected,
};

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/std/fs/File.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions lib/std/posix.zig
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,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.
Expand Down Expand Up @@ -934,7 +934,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,
Expand Down Expand Up @@ -1014,7 +1014,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,
Expand Down Expand Up @@ -1156,7 +1156,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,
Expand Down Expand Up @@ -1278,7 +1278,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.
Expand Down Expand Up @@ -1354,7 +1354,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.
Expand Down Expand Up @@ -1444,7 +1444,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.
Expand Down Expand Up @@ -1529,7 +1529,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.
Expand Down Expand Up @@ -1608,6 +1608,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.
Expand Down Expand Up @@ -1667,6 +1670,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,
Expand Down Expand Up @@ -1838,6 +1842,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,
Expand Down Expand Up @@ -5478,6 +5483,7 @@ pub const RealPathError = error{
FileSystem,
BadPathName,
DeviceBusy,
ProcessNotFound,

SharingViolation,
PipeBusy,
Expand Down
2 changes: 2 additions & 0 deletions lib/std/zig/system.zig
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
error.NoDevice,
=> return error.GLibCNotFound,

error.ProcessNotFound,
error.ProcessFdQuotaExceeded,
error.SystemFdQuotaExceeded,
error.SystemResources,
Expand Down Expand Up @@ -881,6 +882,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {

error.FileTooBig => return error.Unexpected,

error.ProcessNotFound,
error.ProcessFdQuotaExceeded,
error.SystemFdQuotaExceeded,
error.SystemResources,
Expand Down