]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
utmp-wtmp: handle EINTR gracefully when waiting to write to tty
authorLennart Poettering <lennart@poettering.net>
Tue, 22 Nov 2022 11:56:55 +0000 (12:56 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 22 Nov 2022 12:11:04 +0000 (13:11 +0100)
src/shared/utmp-wtmp.c

index 20add0e81b0f0faf7724251a360e18cc76a34180..37a5bf79904504d07fbfa2d848f704582f0e3ca7 100644 (file)
@@ -12,6 +12,7 @@
 #include <utmpx.h>
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "hostname-util.h"
 #include "io-util.h"
@@ -300,7 +301,7 @@ static int write_to_terminal(const char *tty, const char *message) {
         p = message;
         left = strlen(message);
 
-        end = now(CLOCK_MONOTONIC) + TIMEOUT_USEC;
+        end = usec_add(now(CLOCK_MONOTONIC), TIMEOUT_USEC);
 
         while (left > 0) {
                 ssize_t n;
@@ -308,19 +309,21 @@ static int write_to_terminal(const char *tty, const char *message) {
                 int k;
 
                 t = now(CLOCK_MONOTONIC);
-
                 if (t >= end)
                         return -ETIME;
 
                 k = fd_wait_for_event(fd, POLLOUT, end - t);
-                if (k < 0)
+                if (k < 0) {
+                        if (ERRNO_IS_TRANSIENT(k))
+                                continue;
                         return k;
+                }
                 if (k == 0)
                         return -ETIME;
 
                 n = write(fd, p, left);
                 if (n < 0) {
-                        if (errno == EAGAIN)
+                        if (ERRNO_IS_TRANSIENT(errno))
                                 continue;
 
                         return -errno;