Skip to content

Commit e22d79d

Browse files
authored
std.posix: Added error message 'ProcessNotFound' for reading and writing in a Linux process (#21430)
* Added error message 'ProcessNotFound' for reading and writing in a Linux process. This error occurs if the process to be read from or written to no longer exists. Fixes #19875 * Added error message "ProcessNotFound" for error forwarding. * Add error messgae for forwarding. * Added message for forwarding. * Error set completed. * Fixed format error. * Changed comments to doc comments.
1 parent 8ee52f9 commit e22d79d

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lib/compiler/fmt.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ const FmtError = error{
207207
LockViolation,
208208
NetNameDeleted,
209209
InvalidArgument,
210+
ProcessNotFound,
210211
} || fs.File.OpenError;
211212

212213
fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool, dir: fs.Dir, sub_path: []const u8) FmtError!void {

lib/std/posix.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,10 @@ pub const ReadError = error{
798798
/// In WASI, this error occurs when the file descriptor does
799799
/// not hold the required rights to read from it.
800800
AccessDenied,
801+
802+
/// This error occurs in Linux if the process to be read from
803+
/// no longer exists.
804+
ProcessNotFound,
801805
} || UnexpectedError;
802806

803807
/// Returns the number of bytes that were read, which can be less than
@@ -854,6 +858,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
854858
.INTR => continue,
855859
.INVAL => unreachable,
856860
.FAULT => unreachable,
861+
.NOENT => return error.ProcessNotFound,
857862
.AGAIN => return error.WouldBlock,
858863
.CANCELED => return error.Canceled,
859864
.BADF => return error.NotOpenForReading, // Can be a race condition.
@@ -917,6 +922,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
917922
.INTR => continue,
918923
.INVAL => unreachable,
919924
.FAULT => unreachable,
925+
.NOENT => return error.ProcessNotFound,
920926
.AGAIN => return error.WouldBlock,
921927
.BADF => return error.NotOpenForReading, // can be a race condition
922928
.IO => return error.InputOutput,
@@ -996,6 +1002,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
9961002
.INTR => continue,
9971003
.INVAL => unreachable,
9981004
.FAULT => unreachable,
1005+
.NOENT => return error.ProcessNotFound,
9991006
.AGAIN => return error.WouldBlock,
10001007
.BADF => return error.NotOpenForReading, // Can be a race condition.
10011008
.IO => return error.InputOutput,
@@ -1133,6 +1140,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
11331140
.INTR => continue,
11341141
.INVAL => unreachable,
11351142
.FAULT => unreachable,
1143+
.NOENT => return error.ProcessNotFound,
11361144
.AGAIN => return error.WouldBlock,
11371145
.BADF => return error.NotOpenForReading, // can be a race condition
11381146
.IO => return error.InputOutput,
@@ -1176,6 +1184,10 @@ pub const WriteError = error{
11761184

11771185
/// Connection reset by peer.
11781186
ConnectionResetByPeer,
1187+
1188+
/// This error occurs in Linux if the process being written to
1189+
/// no longer exists.
1190+
ProcessNotFound,
11791191
} || UnexpectedError;
11801192

11811193
/// Write to a file descriptor.
@@ -1243,6 +1255,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
12431255
.INTR => continue,
12441256
.INVAL => return error.InvalidArgument,
12451257
.FAULT => unreachable,
1258+
.NOENT => return error.ProcessNotFound,
12461259
.AGAIN => return error.WouldBlock,
12471260
.BADF => return error.NotOpenForWriting, // can be a race condition.
12481261
.DESTADDRREQ => unreachable, // `connect` was never called.
@@ -1315,6 +1328,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
13151328
.INTR => continue,
13161329
.INVAL => return error.InvalidArgument,
13171330
.FAULT => unreachable,
1331+
.NOENT => return error.ProcessNotFound,
13181332
.AGAIN => return error.WouldBlock,
13191333
.BADF => return error.NotOpenForWriting, // Can be a race condition.
13201334
.DESTADDRREQ => unreachable, // `connect` was never called.
@@ -1404,6 +1418,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
14041418
.INTR => continue,
14051419
.INVAL => return error.InvalidArgument,
14061420
.FAULT => unreachable,
1421+
.NOENT => return error.ProcessNotFound,
14071422
.AGAIN => return error.WouldBlock,
14081423
.BADF => return error.NotOpenForWriting, // Can be a race condition.
14091424
.DESTADDRREQ => unreachable, // `connect` was never called.
@@ -1488,6 +1503,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
14881503
.INTR => continue,
14891504
.INVAL => return error.InvalidArgument,
14901505
.FAULT => unreachable,
1506+
.NOENT => return error.ProcessNotFound,
14911507
.AGAIN => return error.WouldBlock,
14921508
.BADF => return error.NotOpenForWriting, // Can be a race condition.
14931509
.DESTADDRREQ => unreachable, // `connect` was never called.

lib/std/zig/system.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ pub const DetectError = error{
172172
DeviceBusy,
173173
OSVersionDetectionFail,
174174
Unexpected,
175+
ProcessNotFound,
175176
};
176177

177178
/// Given a `Target.Query`, which specifies in detail which parts of the
@@ -443,6 +444,7 @@ pub const AbiAndDynamicLinkerFromFileError = error{
443444
Unexpected,
444445
UnexpectedEndOfFile,
445446
NameTooLong,
447+
ProcessNotFound,
446448
};
447449

448450
pub fn abiAndDynamicLinkerFromFile(
@@ -831,6 +833,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
831833
error.UnableToReadElfFile,
832834
error.Unexpected,
833835
error.FileSystem,
836+
error.ProcessNotFound,
834837
=> |e| return e,
835838
};
836839
}
@@ -1077,6 +1080,7 @@ fn detectAbiAndDynamicLinker(
10771080
const len = preadAtLeast(file, &buffer, 0, min_len) catch |err| switch (err) {
10781081
error.UnexpectedEndOfFile,
10791082
error.UnableToReadElfFile,
1083+
error.ProcessNotFound,
10801084
=> return defaultAbiAndDynamicLinker(cpu, os, query),
10811085

10821086
else => |e| return e,
@@ -1120,6 +1124,7 @@ fn detectAbiAndDynamicLinker(
11201124
error.SymLinkLoop,
11211125
error.ProcessFdQuotaExceeded,
11221126
error.SystemFdQuotaExceeded,
1127+
error.ProcessNotFound,
11231128
=> |e| return e,
11241129

11251130
error.UnableToReadElfFile,
@@ -1176,6 +1181,7 @@ fn preadAtLeast(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usi
11761181
error.Unexpected => return error.Unexpected,
11771182
error.InputOutput => return error.FileSystem,
11781183
error.AccessDenied => return error.Unexpected,
1184+
error.ProcessNotFound => return error.ProcessNotFound,
11791185
};
11801186
if (len == 0) return error.UnexpectedEndOfFile;
11811187
i += len;

0 commit comments

Comments
 (0)