shared/wall: use loop_write_full

This commit is contained in:
Mike Yuan
2023-09-05 13:07:02 +08:00
parent e22c60a9d5
commit 3a1fc3860f

View 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