From 27f2a1868f8747afe8b813b6a401797d72024163 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Sun, 16 Mar 2025 18:51:11 +0100 Subject: [PATCH 01/12] Added 'error.ProcessNotFound' where necessary --- lib/std/posix.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/std/posix.zig b/lib/std/posix.zig index f920784ca542..e7725536a5d7 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -866,6 +866,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { .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. @@ -1010,6 +1011,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { .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, @@ -1149,6 +1151,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { .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, @@ -1270,6 +1273,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { .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. @@ -1346,6 +1350,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { .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. @@ -1436,6 +1441,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { .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. @@ -1521,6 +1527,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz .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. From 812e50912613dacc354e396736654e70f8ab45c1 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Wed, 26 Mar 2025 22:40:41 +0100 Subject: [PATCH 02/12] Added error.ProcessNotFound for use in POSIX and fixed other inconsistencies. After extensive testing, the error messages for processes that are already open but no longer available for reading/writing have been adjusted to 'ProcessNotFound' if the error code ESRCH is thrown by the Linux kernel. Incorrect ENOENT error codes that also returned 'ProcessNotFound' have been removed. --- lib/std/fs/Dir.zig | 2 ++ lib/std/posix.zig | 15 +++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index 4ebec1ce14f0..bccec78f3505 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -783,6 +783,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 { @@ -1564,6 +1565,7 @@ fn openDirFlagsZ(self: Dir, sub_path_c: [*:0]const u8, flags: posix.O) OpenError error.FileLocksNotSupported => unreachable, // locking folders is not supported error.WouldBlock => unreachable, // can't happen for directories error.FileBusy => unreachable, // can't happen for directories + error.ProcessNotFound => unreachable, // can't happen for directories else => |e| return e, }; return Dir{ .fd = fd }; diff --git a/lib/std/posix.zig b/lib/std/posix.zig index e7725536a5d7..581bb7c13d76 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -865,7 +865,6 @@ 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, @@ -930,7 +929,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, @@ -1010,7 +1009,6 @@ 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. @@ -1150,7 +1148,6 @@ 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 @@ -1272,7 +1269,6 @@ 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. @@ -1349,7 +1345,6 @@ 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. @@ -1440,7 +1435,6 @@ 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. @@ -1526,7 +1520,6 @@ 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. @@ -1605,6 +1598,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. @@ -1664,6 +1660,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, @@ -1835,6 +1832,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, @@ -5544,6 +5542,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[max_path_bytes]u8) RealP error.WouldBlock => unreachable, error.FileBusy => unreachable, // not asking for write permissions error.InvalidUtf8 => unreachable, // WASI-only + error.ProcessNotFound => unreachable, else => |e| return e, }; defer close(fd); From f88e101da8574fe790355c9b05cdb7057fabc489 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Thu, 27 Mar 2025 14:20:43 +0100 Subject: [PATCH 03/12] Added ProcessNotFound to Dir --- lib/std/fs/Dir.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index 52a35927184a..fb53cfd34cb8 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -2395,6 +2395,7 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File error.BadPathName, error.DeviceBusy, error.NetworkNotFound, + error.ProcessNotFound, => |e| return e, }; } else { @@ -2422,6 +2423,7 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File error.BadPathName, error.NetworkNotFound, error.Unexpected, + error.ProcessNotFound, => |e| return e, } } From 81aac94588a69c643527d646ae3b42f9d77ad1c5 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Thu, 27 Mar 2025 14:44:00 +0100 Subject: [PATCH 04/12] Added missing ProcessNotFound to system.zig --- lib/std/fs/Dir.zig | 2 -- lib/std/zig/system.zig | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index fb53cfd34cb8..52a35927184a 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -2395,7 +2395,6 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File error.BadPathName, error.DeviceBusy, error.NetworkNotFound, - error.ProcessNotFound, => |e| return e, }; } else { @@ -2423,7 +2422,6 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File error.BadPathName, error.NetworkNotFound, error.Unexpected, - error.ProcessNotFound, => |e| return e, } } diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 427b260de006..7857d7df61bc 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -845,6 +845,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion { error.NoDevice, => return error.GLibCNotFound, + error.ProcessNotFound, error.ProcessFdQuotaExceeded, error.SystemFdQuotaExceeded, error.SystemResources, @@ -888,6 +889,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion { error.FileTooBig => return error.Unexpected, + error.ProcessNotFound, error.ProcessFdQuotaExceeded, error.SystemFdQuotaExceeded, error.SystemResources, From 9ec3f37c49b5154234fa5749033f76e01dae860e Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Thu, 27 Mar 2025 15:28:35 +0100 Subject: [PATCH 05/12] Added missing ProcessNotFound also to deleteTree --- lib/std/fs/Dir.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index 52a35927184a..b819e53ae7b3 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -2007,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. @@ -2081,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, @@ -2385,6 +2387,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, From 1f2ef894f31797491ff58f1a3a5b22d15b3ddd78 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Thu, 27 Mar 2025 15:38:09 +0100 Subject: [PATCH 06/12] Added more missing ProcessNotFound to Dir.zig --- lib/std/fs/Dir.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index b819e53ae7b3..00c06e76e9a8 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -2179,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, @@ -2286,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, From 3316e5eaaf4ecd859032ad78e2332dbc2a6b4cb3 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Thu, 27 Mar 2025 23:00:45 +0100 Subject: [PATCH 07/12] Added another missing ProcessNotFound to Dir --- lib/std/fs/Dir.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index 00c06e76e9a8..d359b6bbea69 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -1698,6 +1698,7 @@ pub const DeleteDirError = error{ BadPathName, /// On Windows, `\\server` or `\\server\share` was not found. NetworkNotFound, + ProcessNotFound, Unexpected, }; From 3ccb6148c6435450a76d661a10d03becf3417fad Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Fri, 28 Mar 2025 00:33:09 +0100 Subject: [PATCH 08/12] Added ProcessNotFound to RealPathError --- lib/std/posix.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/std/posix.zig b/lib/std/posix.zig index a9dbb3264d00..6ed318e1e26e 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -5480,6 +5480,7 @@ pub const RealPathError = error{ FileSystem, BadPathName, DeviceBusy, + ProcessNotFound, SharingViolation, PipeBusy, From 37ca0870e24f4138cf5c60aee7331c62d7920bfe Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Fri, 28 Mar 2025 00:45:29 +0100 Subject: [PATCH 09/12] Added ProcessNotFound to OpenError --- lib/std/fs/File.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/std/fs/File.zig b/lib/std/fs/File.zig index 9797a1b89688..5f0020ee6af3 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 From 2111d95e862d00468d86a86e73f8488bfef66192 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Fri, 28 Mar 2025 00:51:43 +0100 Subject: [PATCH 10/12] Added ProcessNotFound to SelfExePathError --- lib/std/fs.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index fc2da3de72bb..b33383dc2dbc 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 From 92d1276b8a871b9acceb2c91b001518b1bc1af49 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Wed, 2 Apr 2025 16:04:25 +0200 Subject: [PATCH 11/12] Removed not neccessary FrocessNotFound from Dir.zig --- lib/std/fs/Dir.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index d359b6bbea69..91a638639cd2 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -1566,7 +1566,6 @@ fn openDirFlagsZ(self: Dir, sub_path_c: [*:0]const u8, flags: posix.O) OpenError error.FileLocksNotSupported => unreachable, // locking folders is not supported error.WouldBlock => unreachable, // can't happen for directories error.FileBusy => unreachable, // can't happen for directories - error.ProcessNotFound => unreachable, // can't happen for directories else => |e| return e, }; return Dir{ .fd = fd }; From dd4fa724c11b7433202fb481dee787a8665c19a3 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Thu, 3 Apr 2025 10:42:41 +0200 Subject: [PATCH 12/12] Removed not neccessary FrocessNotFound from posix.zig --- lib/std/posix.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 92d9d37b9ce1..7200b87da64a 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -5564,7 +5564,6 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[max_path_bytes]u8) RealP error.WouldBlock => unreachable, error.FileBusy => unreachable, // not asking for write permissions error.InvalidUtf8 => unreachable, // WASI-only - error.ProcessNotFound => unreachable, else => |e| return e, }; defer close(fd);