systemd/SOURCES/0932-utmp-wtmp-handle-EINTR-gracefully-when-waiting-to-wr.patch
2023-11-14 20:04:46 +00:00

53 lines
1.7 KiB
Diff

From 3590a9c5ce038bc56cdded426156cbd278903c86 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Tue, 22 Nov 2022 12:56:55 +0100
Subject: [PATCH] utmp-wtmp: handle EINTR gracefully when waiting to write to
tty
(cherry picked from commit 22ecfa83123dbfa2322346ac4e25ad2193a3b10c)
Related: #2172846
---
src/shared/utmp-wtmp.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c
index 743b784489..7358ece75d 100644
--- a/src/shared/utmp-wtmp.c
+++ b/src/shared/utmp-wtmp.c
@@ -320,7 +320,7 @@ static int write_to_terminal(const char *tty, const char *message) {
p = message;
left = strlen(message);
- end = now(CLOCK_MONOTONIC) + TIMEOUT_MSEC*USEC_PER_MSEC;
+ end = usec_add(now(CLOCK_MONOTONIC), TIMEOUT_MSEC*USEC_PER_MSEC);
while (left > 0) {
ssize_t n;
@@ -332,20 +332,22 @@ static int write_to_terminal(const char *tty, const char *message) {
int k;
t = now(CLOCK_MONOTONIC);
-
if (t >= end)
return -ETIME;
k = poll(&pollfd, 1, (end - t) / USEC_PER_MSEC);
- if (k < 0)
+ if (k < 0) {
+ if (ERRNO_IS_TRANSIENT(k))
+ continue;
return -errno;
+ }
if (k == 0)
return -ETIME;
n = write(fd, p, left);
if (n < 0) {
- if (errno == EAGAIN)
+ if (ERRNO_IS_TRANSIENT(errno))
continue;
return -errno;