diff options
Diffstat (limited to 'bin/ptee.c')
-rw-r--r-- | bin/ptee.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/bin/ptee.c b/bin/ptee.c index 8374bd8f..c4749d62 100644 --- a/bin/ptee.c +++ b/bin/ptee.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 C. McEnroe <june@causal.agency> +/* Copyright (C) 2019 June McEnroe <june@causal.agency> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -24,7 +24,6 @@ #include <sys/ioctl.h> #include <sys/time.h> #include <sys/wait.h> -#include <sysexits.h> #include <termios.h> #include <unistd.h> @@ -52,35 +51,35 @@ int main(int argc, char *argv[]) { for (int opt; 0 < (opt = getopt(argc, argv, "t:"));) { switch (opt) { break; case 't': timer = atoi(optarg); - break; default: return EX_USAGE; + break; default: return 1; } } argc -= optind; argv += optind; - if (argc < 1) return EX_USAGE; - if (isatty(STDOUT_FILENO)) errx(EX_USAGE, "stdout is not redirected"); + if (argc < 1) return 1; + if (isatty(STDOUT_FILENO)) errx(1, "stdout is not redirected"); int error = tcgetattr(STDIN_FILENO, &saveTerm); - if (error) err(EX_IOERR, "tcgetattr"); + if (error) err(1, "tcgetattr"); atexit(restoreTerm); struct termios raw = saveTerm; cfmakeraw(&raw); error = tcsetattr(STDIN_FILENO, TCSADRAIN, &raw); - if (error) err(EX_IOERR, "tcsetattr"); + if (error) err(1, "tcsetattr"); struct winsize window; error = ioctl(STDIN_FILENO, TIOCGWINSZ, &window); - if (error) err(EX_IOERR, "ioctl"); + if (error) err(1, "ioctl"); int pty; pid_t pid = forkpty(&pty, NULL, NULL, &window); - if (pid < 0) err(EX_OSERR, "forkpty"); + if (pid < 0) err(1, "forkpty"); if (!pid) { execvp(argv[0], argv); - err(EX_NOINPUT, "%s", argv[0]); + err(1, "%s", argv[0]); } if (timer) { @@ -103,17 +102,17 @@ int main(int argc, char *argv[]) { }; for (;;) { int nfds = poll(fds, 2, -1); - if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll"); + if (nfds < 0 && errno != EINTR) err(1, "poll"); if (nfds < 0) { ssize_t wlen = write(STDOUT_FILENO, mc, sizeof(mc) - 1); - if (wlen < 0) err(EX_IOERR, "write"); + if (wlen < 0) err(1, "write"); continue; } if (fds[0].revents & POLLIN) { ssize_t rlen = read(STDIN_FILENO, buf, sizeof(buf)); - if (rlen < 0) err(EX_IOERR, "read"); + if (rlen < 0) err(1, "read"); if (rlen == 1 && buf[0] == CTRL('Q')) { stop ^= true; @@ -122,30 +121,30 @@ int main(int argc, char *argv[]) { if (rlen == 1 && buf[0] == CTRL('S')) { ssize_t wlen = write(STDOUT_FILENO, mc, sizeof(mc) - 1); - if (wlen < 0) err(EX_IOERR, "write"); + if (wlen < 0) err(1, "write"); continue; } ssize_t wlen = write(pty, buf, rlen); - if (wlen < 0) err(EX_IOERR, "write"); + if (wlen < 0) err(1, "write"); } if (fds[1].revents & POLLIN) { ssize_t rlen = read(pty, buf, sizeof(buf)); - if (rlen < 0) err(EX_IOERR, "read"); + if (rlen < 0) err(1, "read"); ssize_t wlen = write(STDIN_FILENO, buf, rlen); - if (wlen < 0) err(EX_IOERR, "write"); + if (wlen < 0) err(1, "write"); if (!stop) { wlen = write(STDOUT_FILENO, buf, rlen); - if (wlen < 0) err(EX_IOERR, "write"); + if (wlen < 0) err(1, "write"); } } int status; pid_t dead = waitpid(pid, &status, WNOHANG); - if (dead < 0) err(EX_OSERR, "waitpid"); - if (dead) return WIFEXITED(status) ? WEXITSTATUS(status) : EX_SOFTWARE; + if (dead < 0) err(1, "waitpid"); + if (dead) return WIFEXITED(status) ? WEXITSTATUS(status) : 1; } } |