]> 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>
Tue, 10 Apr 2012 14:18:59 +0000 (10:18 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 10 Apr 2012 14:18:59 +0000 (10:18 -0400)
gone away.  Handle write() on the tty returning EIO.

src/exec_pty.c

index 51733f63a5620c5cb5a22fdc7ccc73a87e1966e8..ba77b014c4f4f3fe247798b442057b76668d2d5f 100644 (file)
@@ -437,16 +437,15 @@ perform_io(fd_set *fdsr, fd_set *fdsw, struct command_status *cstat)
            } while (n == -1 && errno == EINTR);
            switch (n) {
                case -1:
-                   if (errno == EAGAIN)
-                       break;
-                   if (errno != ENXIO && errno != EBADF) {
+                   if (errno != EAGAIN) {
+                       /* treat read error as fatal and close the fd */
                        sudo_debug_printf(SUDO_DEBUG_ERROR,
                            "error reading fd %d: %s", iob->rfd,
                            strerror(errno));
-                       errors++;
-                       break;
+                       safe_close(iob->rfd);
+                       iob->rfd = -1;
                    }
-                   /* FALLTHROUGH */
+                   break;
                case 0:
                    /* got EOF or pty has gone away */
                    sudo_debug_printf(SUDO_DEBUG_INFO,
@@ -469,7 +468,7 @@ perform_io(fd_set *fdsr, fd_set *fdsw, struct command_status *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) {
                    sudo_debug_printf(SUDO_DEBUG_INFO,
                        "unable to write %d bytes to fd %d",
                            iob->len - iob->off, iob->wfd);