From 9afe6a842e1a927f81b1a42d2cad39046f5e8e56 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 11 Oct 2009 13:02:06 +0000 Subject: [PATCH] Back out revision 1.10 as the signal that interrupts us may be SIGTTOU or SIGTTIN which the caller must handle. --- term.c | 142 +++++++++++++++++---------------------------------------- 1 file changed, 42 insertions(+), 100 deletions(-) diff --git a/term.c b/term.c index 3a08c4025..37ae404f2 100644 --- a/term.c +++ b/term.c @@ -47,7 +47,6 @@ # include # endif /* HAVE_TERMIO_H */ #endif /* HAVE_TERMIOS_H */ -#include #include "sudo.h" @@ -109,13 +108,8 @@ int term_restore(fd) int fd; { - int rval; - if (changed) { - do { - rval = tcsetattr(fd, TCSAFLUSH|TCSASOFT, &oterm); - } while (rval == -1 && errno == EINTR); - if (rval) + if (tcsetattr(fd, TCSAFLUSH|TCSASOFT, &oterm) != 0) return(0); changed = 0; } @@ -126,27 +120,18 @@ int term_noecho(fd) int fd; { - int rval; - - if (!changed) { - do { - rval = tcgetattr(fd, &oterm); - } while (rval == -1 && errno == EINTR); - if (rval) - return(0); - } + if (!changed && tcgetattr(fd, &oterm) != 0) + return(0); (void) memcpy(&term, &oterm, sizeof(term)); CLR(term.c_lflag, ECHO|ECHONL); #ifdef VSTATUS term.c_cc[VSTATUS] = _POSIX_VDISABLE; #endif - do { - rval = tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term); - } while (rval == -1 && errno == EINTR); - if (rval) - return(0); - changed = 1; - return(1); + if (tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term) == 0) { + changed = 1; + return(1); + } + return(0); } #if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H) @@ -157,15 +142,9 @@ term_raw(fd, onlcr) int onlcr; { struct termios term; - int rval; - if (!changed) { - do { - rval = tcgetattr(fd, &oterm); - } while (rval == -1 && errno == EINTR); - if (rval) - return(0); - } + if (!changed && tcgetattr(fd, &oterm) != 0) + return(0); (void) memcpy(&term, &oterm, sizeof(term)); /* Set terminal to raw mode */ term.c_iflag &= ~(ICRNL|IGNCR|INLCR|IUCLC|IXON); @@ -177,28 +156,19 @@ term_raw(fd, onlcr) term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 0; - do { - rval = tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term); - } while (rval == -1 && errno == EINTR); - if (rval) - return(0); - changed = 1; - return(1); + if (tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term) == 0) { + changed = 1; + return(1); + } + return(0); } int term_cbreak(fd) int fd; { - int rval; - - if (!changed) { - do { - rval = tcgetattr(fd, &oterm); - } while (rval == -1 && errno == EINTR); - if (rval) - return(0); - } + if (!changed && tcgetattr(fd, &oterm) != 0) + return(0); (void) memcpy(&term, &oterm, sizeof(term)); /* Set terminal to half-cooked mode */ term.c_cc[VMIN] = 1; @@ -208,15 +178,13 @@ term_cbreak(fd) #ifdef VSTATUS term.c_cc[VSTATUS] = _POSIX_VDISABLE; #endif - do { - rval = tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term); - } while (rval == -1 && errno == EINTR); - if (rval) - return(0); - term_erase = term.c_cc[VERASE]; - term_kill = term.c_cc[VKILL]; - changed = 1; - return(1); + if (tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term) == 0) { + term_erase = term.c_cc[VERASE]; + term_kill = term.c_cc[VKILL]; + changed = 1; + return(1); + } + return(0); } int @@ -226,20 +194,13 @@ term_copy(src, dst, onlcr) int onlcr; { struct termios tt; - int rval; - do { - rval = tcgetattr(src, &tt); - } while (rval == -1 && errno == EINTR); - if (rval) + if (tcgetattr(src, &tt) != 0) return(0); /* Do not convert line endings from NL to NLCR. */ if (!onlcr) CLR(tt.c_oflag, ONLCR); - do { - rval = tcsetattr(dst, TCSAFLUSH|TCSASOFT, &tt); - } while (rval == -1 && errno == EINTR); - if (rval) + if (tcsetattr(dst, TCSAFLUSH|TCSASOFT, &tt) != 0) return(0); return(1); } @@ -251,15 +212,8 @@ term_raw(fd, onlcr) int fd; int onlcr; { - int rval; - - if (!changed) { - do { - rval = ioctl(fd, TIOCGETP, &oterm); - } while (rval == -1 && errno == EINTR); - if (rval) - return(0); - } + if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0) + return(0); (void) memcpy(&term, &oterm, sizeof(term)); /* Set terminal to raw mode */ CLR(term.c_lflag, ECHO); @@ -267,41 +221,30 @@ term_raw(fd, onlcr) /* Retain NL to NLCR conversion if onlcr flag set. */ if (onlcr) SET(term.sg_flags, CRMOD); - do { - rval = ioctl(fd, TIOCSETP, &term); - } while (rval == -1 && errno == EINTR); - if (rval) - return(0); - changed = 1; - return(1); + if (ioctl(fd, TIOCSETP, &term) == 0) { + changed = 1; + return(1); + } + return(0); } int term_cbreak(fd) int fd; { - int rval; - - if (!changed) { - do { - rval = ioctl(fd, TIOCGETP, &oterm); - } while (rval == -1 && errno == EINTR); - if (rval) - return(0); - } + if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0) + return(0); (void) memcpy(&term, &oterm, sizeof(term)); /* Set terminal to half-cooked mode */ CLR(term.c_lflag, ECHO); SET(term.sg_flags, CBREAK); - do { - rval = ioctl(fd, TIOCSETP, &term); - } while (rval == -1 && errno == EINTR); - if (rval) - return(0); - term_erase = term.sg_erase; - term_kill = term.sg_kill; - changed = 1; - return(1); + if (ioctl(fd, TIOCSETP, &term) == 0) { + term_erase = term.sg_erase; + term_kill = term.sg_kill; + changed = 1; + return(1); + } + return(0); } int @@ -315,7 +258,6 @@ term_copy(src, dst, onlcr) struct ltchars lc; int l, lb; - /* XXX - handle EINTR */ if (ioctl(src, TIOCGETP, &b) != 0 || ioctl(src, TIOCGETC, &tc) != 0 || ioctl(src, TIOCGETD, &l) != 0 || ioctl(src, TIOCGLTC, &lc) != 0 || ioctl(src, TIOCLGET, &lb)) { -- 2.40.0