From 3a1fc3860fc52bc4b89a712fbf256078998b2352 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 5 Sep 2023 13:07:02 +0800 Subject: [PATCH] shared/wall: use loop_write_full --- src/shared/wall.c | 42 +----------------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/src/shared/wall.c b/src/shared/wall.c index e99fd9029c6..e2efd96d371 100644 --- a/src/shared/wall.c +++ b/src/shared/wall.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include @@ -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 -- 2.47.3