diff options
Diffstat (limited to '')
-rw-r--r-- | ingest.c | 52 |
1 files changed, 11 insertions, 41 deletions
diff --git a/ingest.c b/ingest.c index 52a50af..dfc480c 100644 --- a/ingest.c +++ b/ingest.c @@ -15,34 +15,27 @@ */ #include <err.h> -#include <errno.h> #include <fcntl.h> -#include <poll.h> -#include <sys/ioctl.h> #include <sys/ioctl.h> #include <sysexits.h> #include <unistd.h> -extern int winch(void); - static struct { - int winch; int local; int remote; -} fd = { -1, -1, STDIN_FILENO }; +} fd = { -1, STDIN_FILENO }; int main(int argc, char *argv[]) { if (argc < 2) errx(EX_USAGE, "missing private id"); - if (!isatty(STDERR_FILENO)) errx(EX_USAGE, "no terminal (use ssh -t)"); const char *path = argv[1]; fd.local = open(path, O_WRONLY); if (fd.local < 0) err(EX_NOINPUT, "%s", path); struct winsize window; - int error = ioctl(STDERR_FILENO, TIOCGWINSZ, &window); - if (error) err(EX_IOERR, "TIOCGWINSZ"); - fd.winch = winch(); + ssize_t size = read(fd.remote, &window, sizeof(window)); + if (size < 0) err(EX_IOERR, "read(%d)", fd.remote); + if ((size_t)size < sizeof(window)) errx(EX_IOERR, "short read(%d)", fd.remote); for (;;) { int error = ftruncate(fd.local, 0); @@ -58,39 +51,16 @@ int main(int argc, char *argv[]) { } char buf[4096]; - struct pollfd fds[2] = { - { .fd = fd.remote, .events = POLLIN }, - { .fd = fd.winch, .events = POLLIN }, - }; for (ssize_t totalSize = 0; totalSize < 1024 * 1024;) { - int nfds = poll(fds, 2, -1); - if (nfds < 0) { - if (errno == EINTR) continue; - err(EX_IOERR, "poll"); - } - - if (fds[0].revents & POLLIN) { - ssize_t readSize = read(fd.remote, buf, sizeof(buf)); - if (readSize < 0) err(EX_IOERR, "read(%d)", fd.remote); - if (!readSize) return EX_OK; - - ssize_t writeSize = write(fd.local, buf, readSize); - if (writeSize < 0) err(EX_IOERR, "write(%d)", fd.local); - if (writeSize < readSize) errx(EX_IOERR, "short write(%d)", fd.local); - - totalSize += readSize; - } + ssize_t readSize = read(fd.remote, buf, sizeof(buf)); + if (readSize < 0) err(EX_IOERR, "read(%d)", fd.remote); + if (!readSize) return EX_OK; - if (fds[0].revents & POLLHUP) return EX_OK; + ssize_t writeSize = write(fd.local, buf, readSize); + if (writeSize < 0) err(EX_IOERR, "write(%d)", fd.local); + if (writeSize < readSize) errx(EX_IOERR, "short write(%d)", fd.local); - if (fds[1].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); - } - break; - } + totalSize += readSize; } } } |