]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/wall: use loop_write_full 29071/head
authorMike Yuan <me@yhndnzj.com>
Tue, 5 Sep 2023 05:07:02 +0000 (13:07 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 7 Sep 2023 12:32:45 +0000 (20:32 +0800)
src/shared/wall.c

index e99fd9029c61d54f269183a47dc9482374ac78c6..e2efd96d371cab57ffb91db1ec396fa406679be8 100644 (file)
@@ -1,7 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <errno.h>
-#include <poll.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -22,9 +21,6 @@
 
 static int write_to_terminal(const char *tty, const char *message) {
         _cleanup_close_ int fd = -EBADF;
-        const char *p;
-        size_t left;
-        usec_t end;
 
         assert(tty);
         assert(message);
@@ -35,43 +31,7 @@ static int write_to_terminal(const char *tty, const char *message) {
         if (!isatty(fd))
                 return -ENOTTY;
 
-        p = message;
-        left = strlen(message);
-
-        end = usec_add(now(CLOCK_MONOTONIC), TIMEOUT_USEC);
-
-        while (left > 0) {
-                ssize_t n;
-                usec_t t;
-                int k;
-
-                t = now(CLOCK_MONOTONIC);
-                if (t >= end)
-                        return -ETIME;
-
-                k = fd_wait_for_event(fd, POLLOUT, end - t);
-                if (ERRNO_IS_NEG_TRANSIENT(k))
-                        continue;
-                if (k < 0)
-                        return k;
-                if (k == 0)
-                        return -ETIME;
-
-                n = write(fd, p, left);
-                if (n < 0) {
-                        if (ERRNO_IS_TRANSIENT(errno))
-                                continue;
-
-                        return -errno;
-                }
-
-                assert((size_t) n <= left);
-
-                p += n;
-                left -= n;
-        }
-
-        return 0;
+        return loop_write_full(fd, message, SIZE_MAX, TIMEOUT_USEC);
 }
 
 #if ENABLE_UTMP