diff options
author | June McEnroe <june@causal.agency> | 2018-04-20 00:49:35 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-04-20 00:49:35 -0400 |
commit | 65c418bda9a33fe5b1f8576fb46d22944798f044 (patch) | |
tree | 30f889cd1f4d24833e1e11f435671f30ea510a9a | |
parent | Uncommitted changes from months ago :( (diff) | |
download | stream-65c418bda9a33fe5b1f8576fb46d22944798f044.tar.gz stream-65c418bda9a33fe5b1f8576fb46d22944798f044.zip |
Clean up ptee
Diffstat (limited to '')
-rw-r--r-- | ptee.c | 24 |
1 files 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; } } |