diff options
author | June McEnroe <june@causal.agency> | 2017-07-14 23:50:29 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2017-07-14 23:50:29 -0400 |
commit | 100ecf19175d5b3330444fe18954c9608e5d7b7f (patch) | |
tree | 45a9849d7472f688d2c01faf72e33fbe6faa1157 /home | |
parent | Use CTRL macro (diff) | |
download | src-100ecf19175d5b3330444fe18954c9608e5d7b7f.tar.gz src-100ecf19175d5b3330444fe18954c9608e5d7b7f.zip |
Detect death of child
Diffstat (limited to 'home')
-rwxr-xr-x | home/.bin/dtch.c | 14 |
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); |