mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 00:26:57 +00:00
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.
This commit is contained in:
parent
8ee52f99ce
commit
e22d79dacb
@ -207,6 +207,7 @@ const FmtError = error{
|
||||
LockViolation,
|
||||
NetNameDeleted,
|
||||
InvalidArgument,
|
||||
ProcessNotFound,
|
||||
} || fs.File.OpenError;
|
||||
|
||||
fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool, dir: fs.Dir, sub_path: []const u8) FmtError!void {
|
||||
|
@ -798,6 +798,10 @@ pub const ReadError = error{
|
||||
/// In WASI, this error occurs when the file descriptor does
|
||||
/// not hold the required rights to read from it.
|
||||
AccessDenied,
|
||||
|
||||
/// This error occurs in Linux if the process to be read from
|
||||
/// no longer exists.
|
||||
ProcessNotFound,
|
||||
} || UnexpectedError;
|
||||
|
||||
/// 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 {
|
||||
.INTR => continue,
|
||||
.INVAL => unreachable,
|
||||
.FAULT => unreachable,
|
||||
.NOENT => return error.ProcessNotFound,
|
||||
.AGAIN => return error.WouldBlock,
|
||||
.CANCELED => return error.Canceled,
|
||||
.BADF => return error.NotOpenForReading, // Can be a race condition.
|
||||
@ -917,6 +922,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
|
||||
.INTR => continue,
|
||||
.INVAL => unreachable,
|
||||
.FAULT => unreachable,
|
||||
.NOENT => return error.ProcessNotFound,
|
||||
.AGAIN => return error.WouldBlock,
|
||||
.BADF => return error.NotOpenForReading, // can be a race condition
|
||||
.IO => return error.InputOutput,
|
||||
@ -996,6 +1002,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
|
||||
.INTR => continue,
|
||||
.INVAL => unreachable,
|
||||
.FAULT => unreachable,
|
||||
.NOENT => return error.ProcessNotFound,
|
||||
.AGAIN => return error.WouldBlock,
|
||||
.BADF => return error.NotOpenForReading, // Can be a race condition.
|
||||
.IO => return error.InputOutput,
|
||||
@ -1133,6 +1140,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
|
||||
.INTR => continue,
|
||||
.INVAL => unreachable,
|
||||
.FAULT => unreachable,
|
||||
.NOENT => return error.ProcessNotFound,
|
||||
.AGAIN => return error.WouldBlock,
|
||||
.BADF => return error.NotOpenForReading, // can be a race condition
|
||||
.IO => return error.InputOutput,
|
||||
@ -1176,6 +1184,10 @@ pub const WriteError = error{
|
||||
|
||||
/// Connection reset by peer.
|
||||
ConnectionResetByPeer,
|
||||
|
||||
/// This error occurs in Linux if the process being written to
|
||||
/// no longer exists.
|
||||
ProcessNotFound,
|
||||
} || UnexpectedError;
|
||||
|
||||
/// Write to a file descriptor.
|
||||
@ -1243,6 +1255,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
|
||||
.INTR => continue,
|
||||
.INVAL => return error.InvalidArgument,
|
||||
.FAULT => unreachable,
|
||||
.NOENT => return error.ProcessNotFound,
|
||||
.AGAIN => return error.WouldBlock,
|
||||
.BADF => return error.NotOpenForWriting, // can be a race condition.
|
||||
.DESTADDRREQ => unreachable, // `connect` was never called.
|
||||
@ -1315,6 +1328,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,
|
||||
.AGAIN => return error.WouldBlock,
|
||||
.BADF => return error.NotOpenForWriting, // Can be a race condition.
|
||||
.DESTADDRREQ => unreachable, // `connect` was never called.
|
||||
@ -1404,6 +1418,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,
|
||||
.AGAIN => return error.WouldBlock,
|
||||
.BADF => return error.NotOpenForWriting, // Can be a race condition.
|
||||
.DESTADDRREQ => unreachable, // `connect` was never called.
|
||||
@ -1488,6 +1503,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,
|
||||
.AGAIN => return error.WouldBlock,
|
||||
.BADF => return error.NotOpenForWriting, // Can be a race condition.
|
||||
.DESTADDRREQ => unreachable, // `connect` was never called.
|
||||
|
@ -172,6 +172,7 @@ pub const DetectError = error{
|
||||
DeviceBusy,
|
||||
OSVersionDetectionFail,
|
||||
Unexpected,
|
||||
ProcessNotFound,
|
||||
};
|
||||
|
||||
/// Given a `Target.Query`, which specifies in detail which parts of the
|
||||
@ -443,6 +444,7 @@ pub const AbiAndDynamicLinkerFromFileError = error{
|
||||
Unexpected,
|
||||
UnexpectedEndOfFile,
|
||||
NameTooLong,
|
||||
ProcessNotFound,
|
||||
};
|
||||
|
||||
pub fn abiAndDynamicLinkerFromFile(
|
||||
@ -831,6 +833,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
|
||||
error.UnableToReadElfFile,
|
||||
error.Unexpected,
|
||||
error.FileSystem,
|
||||
error.ProcessNotFound,
|
||||
=> |e| return e,
|
||||
};
|
||||
}
|
||||
@ -1077,6 +1080,7 @@ fn detectAbiAndDynamicLinker(
|
||||
const len = preadAtLeast(file, &buffer, 0, min_len) catch |err| switch (err) {
|
||||
error.UnexpectedEndOfFile,
|
||||
error.UnableToReadElfFile,
|
||||
error.ProcessNotFound,
|
||||
=> return defaultAbiAndDynamicLinker(cpu, os, query),
|
||||
|
||||
else => |e| return e,
|
||||
@ -1120,6 +1124,7 @@ fn detectAbiAndDynamicLinker(
|
||||
error.SymLinkLoop,
|
||||
error.ProcessFdQuotaExceeded,
|
||||
error.SystemFdQuotaExceeded,
|
||||
error.ProcessNotFound,
|
||||
=> |e| return e,
|
||||
|
||||
error.UnableToReadElfFile,
|
||||
@ -1176,6 +1181,7 @@ fn preadAtLeast(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usi
|
||||
error.Unexpected => return error.Unexpected,
|
||||
error.InputOutput => return error.FileSystem,
|
||||
error.AccessDenied => return error.Unexpected,
|
||||
error.ProcessNotFound => return error.ProcessNotFound,
|
||||
};
|
||||
if (len == 0) return error.UnexpectedEndOfFile;
|
||||
i += len;
|
||||
|
Loading…
Reference in New Issue
Block a user