From 6dc9f89da7ecbc9ee859f7e2438e62eb0c9b5a52 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 6 Mar 2018 12:55:33 -0500 Subject: Yet more tweaking of dtch --- bin/dtch.c | 59 +++++++++++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 36 deletions(-) (limited to 'bin') diff --git a/bin/dtch.c b/bin/dtch.c index fb5bc89a..7ec71801 100644 --- a/bin/dtch.c +++ b/bin/dtch.c @@ -132,14 +132,9 @@ static int dtch(int argc, char *argv[]) { addr = sockAddr(user->pw_dir, name); error = bind(server, (struct sockaddr *)&addr, sizeof(addr)); if (error) err(EX_CANTCREAT, "%s", addr.sun_path); + fcntl(server, F_SETFD, FD_CLOEXEC); atexit(unlinkAddr); - error = chmod(addr.sun_path, 0600); - if (error) err(EX_IOERR, "%s", addr.sun_path); - - error = fcntl(server, F_SETFD, FD_CLOEXEC); - if (error) err(EX_IOERR, "fcntl"); - int pty; pid_t pid = forkpty(&pty, NULL, NULL, NULL); if (pid < 0) err(EX_OSERR, "forkpty"); @@ -173,9 +168,8 @@ static int dtch(int argc, char *argv[]) { static struct termios saveTerm; static void restoreTerm(void) { - tcsetattr(STDERR_FILENO, TCSADRAIN, &saveTerm); - fprintf( - stderr, + tcsetattr(STDIN_FILENO, TCSADRAIN, &saveTerm); + printf( "\x1b[?1049l" // rmcup "\x1b\x63\x1b[!p\x1b[?3;4l\x1b[4l\x1b>" // reset ); @@ -198,27 +192,24 @@ static int atch(int argc, char *argv[]) { if (pty < 0) err(EX_IOERR, "recvmsg"); struct winsize window; - error = ioctl(STDERR_FILENO, TIOCGWINSZ, &window); - if (error) err(EX_IOERR, "ioctl(%d, TIOCGWINSZ)", STDERR_FILENO); - - struct winsize redraw = window; - redraw.ws_row = 1; - redraw.ws_col = 1; + error = ioctl(STDIN_FILENO, TIOCGWINSZ, &window); + if (error) err(EX_IOERR, "TIOCGWINSZ"); + struct winsize redraw = { .ws_row = 1, .ws_col = 1 }; error = ioctl(pty, TIOCSWINSZ, &redraw); - if (error) err(EX_IOERR, "iotctl(%d, TIOCSWINSZ)", pty); + if (error) err(EX_IOERR, "TIOCSWINSZ"); error = ioctl(pty, TIOCSWINSZ, &window); - if (error) err(EX_IOERR, "ioctl(%d, TIOCSWINSZ)", pty); + if (error) err(EX_IOERR, "TIOCSWINSZ"); - error = tcgetattr(STDERR_FILENO, &saveTerm); - if (error) err(EX_IOERR, "tcgetattr(%d)", STDERR_FILENO); + error = tcgetattr(STDIN_FILENO, &saveTerm); + if (error) err(EX_IOERR, "tcgetattr"); atexit(restoreTerm); struct termios raw; cfmakeraw(&raw); - error = tcsetattr(STDERR_FILENO, TCSADRAIN, &raw); - if (error) err(EX_IOERR, "tcsetattr(%d)", STDERR_FILENO); + error = tcsetattr(STDIN_FILENO, TCSADRAIN, &raw); + if (error) err(EX_IOERR, "tcsetattr"); char buf[4096]; struct pollfd fds[2] = { @@ -226,26 +217,22 @@ static int atch(int argc, char *argv[]) { { .fd = pty, .events = POLLIN }, }; while (0 < poll(fds, 2, -1)) { - if (fds[0].revents & POLLIN) { - ssize_t readSize = read(STDIN_FILENO, buf, sizeof(buf)); - if (readSize < 0) err(EX_IOERR, "read(%d)", STDIN_FILENO); + if (fds[0].revents) { + ssize_t size = read(STDIN_FILENO, buf, sizeof(buf)); + if (size < 0) err(EX_IOERR, "read(%d)", STDIN_FILENO); - if (readSize == 1 && buf[0] == CTRL('Q')) return EX_OK; + if (size == 1 && buf[0] == CTRL('Q')) return EX_OK; - ssize_t writeSize = write(pty, buf, readSize); - if (writeSize < 0) err(EX_IOERR, "write(%d)", pty); - if (writeSize < readSize) errx(EX_IOERR, "short write(%d)", pty); + size = write(pty, buf, size); + if (size < 0) err(EX_IOERR, "write(%d)", pty); } - if (fds[1].revents & POLLIN) { - ssize_t readSize = read(pty, buf, sizeof(buf)); - if (readSize < 0) err(EX_IOERR, "read(%d)", pty); + if (fds[1].revents) { + ssize_t size = read(pty, buf, sizeof(buf)); + if (size < 0) err(EX_IOERR, "read(%d)", pty); - ssize_t writeSize = write(STDOUT_FILENO, buf, readSize); - if (writeSize < 0) err(EX_IOERR, "write(%d)", STDOUT_FILENO); - if (writeSize < readSize) { - errx(EX_IOERR, "short write(%d)", STDOUT_FILENO); - } + size = write(STDOUT_FILENO, buf, size); + if (size < 0) err(EX_IOERR, "write(%d)", STDOUT_FILENO); } } err(EX_IOERR, "poll"); -- cgit 1.4.1 June McEnroe Since 9c845be2797e2047547ec247cb037471aeb48bb0 in curl (7.71.0), setting CURLOPT_NOBODY to 1 sets the request method to HEAD, but setting it back to 0 does not change the method back to GET. Setting CURLOPT_HTTPGET both sets the request method and unsets CURLOPT_NOBODY. 2020-07-20Set pull.rebase trueJune McEnroe 2020-07-18Read from stdin in orderJune McEnroe 2020-07-18Actually fix nvim and doas presence testsJune McEnroe 2020-07-14Install up CGI with mode 700June McEnroe It should never be served as a regular file. 2020-07-14Check that there is upload dataJune McEnroe 2020-07-14Add CGI upload program for temp.causal.agencyJune McEnroe 2020-07-10Add The Broken KingdomsJune McEnroe 2020-07-08Add facebook and twitter to title user-agentJune McEnroe This fixes fetching tweets again! https://github.com/thelounge/thelounge/pull/ 3602 (Intentionally breaking the link so GitHub doesn't add a "referenced this PR" thing?) 2020-06-30Tweak causal.agency for mostly no reasonJune McEnroe 2020-06-30Add Ancillary JusticeJune McEnroe 2020-06-26Add password non-manager to planJune McEnroe I've had this idea for years... 2020-06-26Tweak TF2 sensitivities once moreJune McEnroe 2020-06-19Add note about litterbox bot useJune McEnroe 2020-06-19Publish "IRC suite"June McEnroe 2020-06-17Add errors to link.shJune McEnroe