diff options
| author | christos <christos@NetBSD.org> | 2005-01-08 06:43:16 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2005-01-08 06:43:16 +0000 |
| commit | ca7489bf5cb1686e31444a5ed6be3147fa5e3d27 (patch) | |
| tree | 3dabbaff4bded13a77ceeb1b31c6b3a5b607ed52 /lib/libutil/ttymsg.c | |
| parent | ed4b87656abcbec99f8d96d0af0ddf409f4772aa (diff) | |
Avoid spinning if writing to a pty returns 0. This happened to me when
I had a pty with a suspended sshd (why?).
Diffstat (limited to 'lib/libutil/ttymsg.c')
| -rw-r--r-- | lib/libutil/ttymsg.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/libutil/ttymsg.c b/lib/libutil/ttymsg.c index 70a62825220..a70a08ab2e8 100644 --- a/lib/libutil/ttymsg.c +++ b/lib/libutil/ttymsg.c @@ -1,4 +1,4 @@ -/* $NetBSD: ttymsg.c,v 1.20 2004/11/10 17:00:41 christos Exp $ */ +/* $NetBSD: ttymsg.c,v 1.21 2005/01/08 06:43:16 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)ttymsg.c 8.2 (Berkeley) 11/16/93"; #else -__RCSID("$NetBSD: ttymsg.c,v 1.20 2004/11/10 17:00:41 christos Exp $"); +__RCSID("$NetBSD: ttymsg.c,v 1.21 2005/01/08 06:43:16 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -122,7 +122,7 @@ ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout) wret = writev(fd, iov, iovcnt); if (wret >= left) break; - if (wret >= 0) { + if (wret > 0) { left -= wret; if (iov != localiov) { (void)memcpy(localiov, iov, @@ -140,6 +140,14 @@ ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout) iov->iov_len -= wret; } continue; + } else if (wret == 0) { + (void)snprintf(errbuf, sizeof(errbuf), + "%s: failed writing %d bytes to `%s'", __func__, + left, device); + (void) close(fd); + if (forked) + _exit(1); + return errbuf; } if (errno == EWOULDBLOCK) { pid_t cpid; |
