Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libutil Avoid spinning if writing to a pty returns 0. Th...



details:   https://anonhg.NetBSD.org/src/rev/ebebaed8a57d
branches:  trunk
changeset: 572567:ebebaed8a57d
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jan 08 06:43:16 2005 +0000

description:
Avoid spinning if writing to a pty returns 0. This happened to me when
I had a pty with a suspended sshd (why?).

diffstat:

 lib/libutil/ttymsg.c |  14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diffs (42 lines):

diff -r a14ec9d330c5 -r ebebaed8a57d lib/libutil/ttymsg.c
--- a/lib/libutil/ttymsg.c      Sat Jan 08 05:33:42 2005 +0000
+++ b/lib/libutil/ttymsg.c      Sat Jan 08 06:43:16 2005 +0000
@@ -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 @@
                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 @@
                                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;



Home | Main Index | Thread Index | Old Index