Skip to content

Commit

Permalink
utmp-wtmp: handle EINTR gracefully when waiting to write to tty
Browse files Browse the repository at this point in the history
(cherry picked from commit 22ecfa83123dbfa2322346ac4e25ad2193a3b10c)

Related: #2172846
  • Loading branch information
poettering authored and systemd-rhel-bot committed Jun 14, 2023
1 parent c57daab commit 3590a9c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/shared/utmp-wtmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ static int write_to_terminal(const char *tty, const char *message) {
p = message;
left = strlen(message);

end = now(CLOCK_MONOTONIC) + TIMEOUT_MSEC*USEC_PER_MSEC;
end = usec_add(now(CLOCK_MONOTONIC), TIMEOUT_MSEC*USEC_PER_MSEC);

while (left > 0) {
ssize_t n;
Expand All @@ -332,20 +332,22 @@ static int write_to_terminal(const char *tty, const char *message) {
int k;

t = now(CLOCK_MONOTONIC);

if (t >= end)
return -ETIME;

k = poll(&pollfd, 1, (end - t) / USEC_PER_MSEC);
if (k < 0)
if (k < 0) {
if (ERRNO_IS_TRANSIENT(k))
continue;
return -errno;

}
if (k == 0)
return -ETIME;

n = write(fd, p, left);
if (n < 0) {
if (errno == EAGAIN)
if (ERRNO_IS_TRANSIENT(errno))
continue;

return -errno;
Expand Down

0 comments on commit 3590a9c

Please sign in to comment.