]> granicus.if.org Git - sudo/commitdiff
Treat a tty read failure like EOF as it usually means the pty has
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 23 May 2012 19:09:30 +0000 (15:09 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 23 May 2012 19:09:30 +0000 (15:09 -0400)
gone away.  Handle write() on the tty returning EIO.

--HG--
branch : 1.7

exec_pty.c

index 51d95cced0342ccb347c2ffe0d72d25d2fc7b72b..46eaa4791c2b36e7d6626ea5a91f6f7d4f007383 100644 (file)
@@ -294,13 +294,12 @@ perform_io(fdsr, fdsw, cstat)
            } while (n == -1 && errno == EINTR);
            switch (n) {
                case -1:
-                   if (errno == EAGAIN)
-                       break;
-                   if (errno != ENXIO && errno != EBADF) {
-                       errors++;
-                       break;
+                   if (errno != EAGAIN) {
+                       /* treat read error as fatal and close the fd */
+                       safe_close(iob->rfd);
+                       iob->rfd = -1;
                    }
-                   /* FALLTHROUGH */
+                   break;
                case 0:
                    /* got EOF or pty has gone away */
                    safe_close(iob->rfd);
@@ -319,7 +318,7 @@ perform_io(fdsr, fdsw, cstat)
                    iob->len - iob->off);
            } while (n == -1 && errno == EINTR);
            if (n == -1) {
-               if (errno == EPIPE || errno == ENXIO || errno == EBADF) {
+               if (errno == EPIPE || errno == ENXIO || errno == EIO || errno == EBADF) {
                    /* other end of pipe closed or pty revoked */
                    if (iob->rfd != -1) {
                        safe_close(iob->rfd);