summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xhome/.bin/dtch.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/home/.bin/dtch.c b/home/.bin/dtch.c
index 071116b4..dc3b5719 100755
--- a/home/.bin/dtch.c
+++ b/home/.bin/dtch.c
@@ -10,6 +10,7 @@ exit
 #include <errno.h>
 #include <fcntl.h>
 #include <poll.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
@@ -150,8 +151,6 @@ static int dtch(int argc, char *argv[]) {
         err(EX_OSERR, "%s", cmd);
     }
 
-    // TODO: Kill child on error after this point?
-
     error = listen(server, 1);
     if (error) err(EX_IOERR, "listen");
 
@@ -162,15 +161,15 @@ static int dtch(int argc, char *argv[]) {
         ssize_t len = sendFd(client, master);
         if (len < 0) warn("sendmsg(%d)", client);
 
-        // TODO: Send SIGWINCH?
-
         len = recv(client, &z, sizeof(z), 0);
         if (len < 0) warn("recv(%d)", client);
 
         error = close(client);
         if (error) warn("close(%d)", client);
 
-        // TODO: Detect death of child.
+        pid_t dead = waitpid(pid, NULL, WNOHANG);
+        if (dead < 0) warn("waitpid(%d)", pid);
+        if (dead) exit(EX_OK);
     }
 }
 
@@ -213,8 +212,6 @@ static int atch(int argc, char *argv[]) {
     error = ioctl(master, TIOCSWINSZ, &window);
     if (error) warn("ioctl(%d, TIOCSWINSZ)", master);
 
-    // TODO: Handle SIGWINCH?
-
     struct pollfd fds[2];
     fds[0].fd = STDIN_FILENO;
     fds[0].events = POLLIN;
@@ -228,8 +225,7 @@ static int atch(int argc, char *argv[]) {
             if (len < 0) err(EX_IOERR, "read(%d)", STDIN_FILENO);
 
             if (len && buf[0] == CTRL('Q')) {
-                // TODO: Message?
-                exit(0);
+                exit(EX_OK);
             }
 
             len = writeAll(master, buf, len);
tJune McEnroe 2019-05-29Add xx -p optionJune McEnroe 2019-05-27Add FrontierJune McEnroe 2019-05-27Break nicks with ZWNJJune McEnroe 2019-05-26Add DawnJune McEnroe 2019-05-20Declare vasprintf(3) for GNUJune McEnroe 2019-05-20Fix comparison warning in ttpreJune McEnroe 2019-05-20Add AuthorityJune McEnroe 2019-05-19Specify precedence of unary versions of operatorsJune McEnroe 2019-05-18Add compound assignment operators to orderJune McEnroe 2019-05-15Support simple assignment in orderJune McEnroe 2019-05-15Implement sizeof in orderJune McEnroe 2019-05-15Add orderJune McEnroe 2019-05-12Add T suffix in bitJune McEnroe 2019-05-10Highlight yacc and lex files as CJune McEnroe 2019-05-10Use val instead of suboptargJune McEnroe 2019-05-09Add Parable of the SowerJune McEnroe 2019-05-07Add bit without buildJune McEnroe 2019-05-04Fix MANDIR typoJune McEnroe 2019-05-04Move relay to binJune McEnroe