Merge pull request #21564 from yuwata/errno-eagain-eintr

tree-wide: introduce ERRNO_IS_TRANSIENT() and use it
This commit is contained in:
Yu Watanabe
2021-12-01 12:52:27 +09:00
committed by GitHub
30 changed files with 129 additions and 108 deletions
+9 -4
View File
@@ -70,6 +70,13 @@ static inline int errno_or_else(int fallback) {
return -abs(fallback);
}
/* For send()/recv() or read()/write(). */
static inline bool ERRNO_IS_TRANSIENT(int r) {
return IN_SET(abs(r),
EAGAIN,
EINTR);
}
/* Hint #1: ENETUNREACH happens if we try to connect to "non-existing" special IP addresses, such as ::5.
*
* Hint #2: The kernel sends e.g., EHOSTUNREACH or ENONET to userspace in some ICMP error cases. See the
@@ -100,10 +107,8 @@ static inline bool ERRNO_IS_DISCONNECT(int r) {
* the accept(2) man page. */
static inline bool ERRNO_IS_ACCEPT_AGAIN(int r) {
return ERRNO_IS_DISCONNECT(r) ||
IN_SET(abs(r),
EAGAIN,
EINTR,
EOPNOTSUPP);
ERRNO_IS_TRANSIENT(r) ||
abs(r) == EOPNOTSUPP;
}
/* Resource exhaustion, could be our fault or general system trouble */
+1 -1
View File
@@ -453,7 +453,7 @@ int acquire_terminal(
l = read(notify, &buffer, sizeof(buffer));
if (l < 0) {
if (IN_SET(errno, EINTR, EAGAIN))
if (ERRNO_IS_TRANSIENT(errno))
continue;
return -errno;