From 65c418bda9a33fe5b1f8576fb46d22944798f044 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Fri, 20 Apr 2018 00:49:35 -0400 Subject: Clean up ptee --- ptee.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/ptee.c b/ptee.c index 785b25a..e04fd2a 100644 --- a/ptee.c +++ b/ptee.c @@ -77,13 +77,12 @@ int main(int argc, char *argv[]) { if (pid < 0) err(EX_OSERR, "forkpty"); if (!pid) { - execvp(*argv, argv); - err(EX_NOINPUT, "%s", *argv); + execvp(argv[0], argv); + err(EX_NOINPUT, "%s", argv[0]); } 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; @@ -92,28 +91,27 @@ int main(int argc, char *argv[]) { { .fd = fd.pty, .events = 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); + if (fds[0].revents) { + ssize_t size = read(fd.input, buf, sizeof(buf)); + if (size < 0) err(EX_IOERR, "read(%d)", fd.input); - ssize_t writeSize = write(fd.pty, buf, readSize); - if (writeSize < 0) err(EX_IOERR, "write(%d)", fd.pty); - if (writeSize < readSize) errx(EX_IOERR, "short write(%d)", fd.pty); + size = write(fd.pty, buf, size); + if (size < 0) err(EX_IOERR, "write(%d)", fd.pty); } - if (fds[1].revents & POLLIN) { + if (fds[1].revents) { ssize_t readSize = read(fd.pty, buf, sizeof(buf)); if (readSize < 0) err(EX_IOERR, "read(%d)", fd.pty); ssize_t writeSize = write(fd.local, buf, readSize); if (writeSize < 0) err(EX_IOERR, "write(%d)", fd.local); - if (writeSize < readSize) err(EX_IOERR, "short write(%d)", fd.local); writeSize = write(fd.remote, buf, readSize); if (writeSize < 0) err(EX_IOERR, "write(%d)", fd.remote); - if (writeSize < readSize) err(EX_IOERR, "short write(%d)", fd.remote); if ((totalSize += readSize) >= 1024 * 1024) { + totalSize = 0; + struct winsize redraw = window; redraw.ws_row = 1; redraw.ws_col = 1; @@ -123,8 +121,6 @@ int main(int argc, char *argv[]) { error = ioctl(fd.pty, TIOCSWINSZ, &window); if (error) err(EX_IOERR, "TIOCSWINSZ"); - - totalSize = 0; } } -- cgit 1.4.1 )Author 2018-09-12Use formatParse split to position input cursorJune McEnroe 2018-09-12Factor out IRC formatting parsingJune McEnroe 2018-09-11Add /help equivalent to /manJune McEnroe 2018-09-11Don't render every PM as a pingJune McEnroe 2018-09-11Add urlOpenMatchJune McEnroe 2018-09-10Depend on man.sh for chroot.tar targetJune McEnroe 2018-09-10Set LESSSECURE=1 in man.shJune McEnroe 2018-09-10Add /man commandJune McEnroe 2018-09-10Install man page in chrootJune McEnroe 2018-09-10Install man pageJune McEnroe 2018-09-10Split keys into subsections and document colorsJune McEnroe 2018-09-10Add "blank" lines to chatte.1June McEnroe 2018-09-10Document key bindings in chatte.1June McEnroe 2018-09-08Document slash commands in chatte.1June McEnroe