From: Mike Yuan Date: Tue, 5 Sep 2023 05:07:02 +0000 (+0800) Subject: shared/wall: use loop_write_full X-Git-Tag: v255-rc1~550^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F29071%2Fhead;p=thirdparty%2Fsystemd.git shared/wall: use loop_write_full --- 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