From e8c73759dc86ea05f7a7778a94ca6ce583a1305b Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 25 Feb 2018 22:10:46 -0500 Subject: Switch back to static window sizing --- ptee.c | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) (limited to 'ptee.c') diff --git a/ptee.c b/ptee.c index 7dec8c1..785b25a 100644 --- a/ptee.c +++ b/ptee.c @@ -15,7 +15,6 @@ */ #include -#include #include #include #include @@ -33,15 +32,12 @@ #include #endif -extern int winch(void); - static struct { int pty; - int winch; int input; int local; int remote; -} fd = { -1, -1, STDIN_FILENO, STDERR_FILENO, STDOUT_FILENO }; +} fd = { -1, STDIN_FILENO, STDERR_FILENO, STDOUT_FILENO }; static struct termios saveTerm; static void restoreTerm(void) { @@ -76,7 +72,6 @@ int main(int argc, char *argv[]) { struct winsize window; error = ioctl(fd.local, TIOCGWINSZ, &window); if (error) err(EX_IOERR, "TIOCGWINSZ"); - fd.winch = winch(); pid_t pid = forkpty(&fd.pty, NULL, NULL, &window); if (pid < 0) err(EX_OSERR, "forkpty"); @@ -86,21 +81,18 @@ int main(int argc, char *argv[]) { err(EX_NOINPUT, "%s", *argv); } + ssize_t size = write(fd.remote, &window, sizeof(window)); + if (size < 0) err(EX_IOERR, "write(%d)", fd.remote); + if ((size_t)size < sizeof(window)) errx(EX_IOERR, "short write(%d)", fd.remote); + char buf[4096]; ssize_t totalSize = 0; - struct pollfd fds[3] = { + struct pollfd fds[2] = { { .fd = fd.input, .events = POLLIN }, { .fd = fd.pty, .events = POLLIN }, - { .fd = fd.winch, .events = POLLIN }, }; - for (;;) { - int nfds = poll(fds, 3, -1); - if (nfds < 0) { - if (errno == EINTR) continue; - err(EX_IOERR, "poll"); - } - - if (fds[0].revents == POLLIN) { + while (0 < poll(fds, 2, -1)) { + if (fds[0].revents & POLLIN) { ssize_t readSize = read(fd.input, buf, sizeof(buf)); if (readSize < 0) err(EX_IOERR, "read(%d)", fd.input); @@ -109,7 +101,7 @@ int main(int argc, char *argv[]) { if (writeSize < readSize) errx(EX_IOERR, "short write(%d)", fd.pty); } - if (fds[1].revents == POLLIN) { + if (fds[1].revents & POLLIN) { ssize_t readSize = read(fd.pty, buf, sizeof(buf)); if (readSize < 0) err(EX_IOERR, "read(%d)", fd.pty); @@ -122,35 +114,24 @@ int main(int argc, char *argv[]) { if (writeSize < readSize) err(EX_IOERR, "short write(%d)", fd.remote); if ((totalSize += readSize) >= 1024 * 1024) { - struct winsize original = window; - window.ws_row = 1; - window.ws_col = 1; + struct winsize redraw = window; + redraw.ws_row = 1; + redraw.ws_col = 1; - int error = ioctl(fd.pty, TIOCSWINSZ, &window); + error = ioctl(fd.pty, TIOCSWINSZ, &redraw); if (error) err(EX_IOERR, "TIOCSWINSZ"); - window = original; error = ioctl(fd.pty, TIOCSWINSZ, &window); - if (error) err(EX_IOERR, "TIOCWINSZ"); + if (error) err(EX_IOERR, "TIOCSWINSZ"); totalSize = 0; } } - if (fds[2].revents == POLLIN) { - ssize_t readSize = read(fd.winch, &window, sizeof(window)); - if (readSize < 0) err(EX_IOERR, "read(%d)", fd.winch); - if ((size_t)readSize < sizeof(window)) { - errx(EX_IOERR, "short read(%d)", fd.winch); - } - - int error = ioctl(fd.pty, TIOCSWINSZ, &window); - if (error) err(EX_IOERR, "TIOCSWINSZ"); - } - int status; pid_t dead = waitpid(pid, &status, WNOHANG); if (dead < 0) err(EX_OSERR, "waitpid(%d)", pid); if (dead) return WIFEXITED(status) ? WEXITSTATUS(status) : EX_SOFTWARE; } + err(EX_IOERR, "poll"); } -- cgit 1.4.1