From 100ecf19175d5b3330444fe18954c9608e5d7b7f Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 14 Jul 2017 23:50:29 -0400 Subject: Detect death of child --- home/.bin/dtch.c | 14 +++++--------- 1 file 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 #include #include +#include #include #include #include @@ -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); -- cgit 1.4.1 1359561b5910a0&follow=1'>txt (unfollow)
Commit message (Expand)Author
2021-01-31Add The Rosewater RedemptionJune McEnroe
2021-01-29Use int when checking for EOFJune McEnroe
2021-01-28Move gpl.c and agpl.c templates out of etcJune McEnroe
2021-01-27Set para and sect for mdocJune McEnroe
2021-01-26Use First state to match keyword at beginning of lineJune McEnroe
2021-01-25Install vi on Linux and nvi on macOSJune McEnroe
2021-01-25Use vi and lessJune McEnroe
2021-01-20Use mtags for sh in source-filterJune McEnroe
2021-01-20Generate tags for sh files in mtagsJune McEnroe
2021-01-20Add messy sh lexerJune McEnroe
2021-01-20Add all target to git.causal.agency MakefileJune McEnroe
2021-01-20Remove Lua supportJune McEnroe
2021-01-20Fix tests for diff spansJune McEnroe
2021-01-20Avoid matching ':' in make tagsJune McEnroe
2021-01-19Prefer tag matches not preceded by [[:alnum:]]June McEnroe
2021-01-19Escape \ and / in mtags search patternsJune McEnroe
2021-01-20Use mtags in source-filterJune McEnroe
2021-01-19Add mtags to generate tags for make and mdocJune McEnroe
2021-01-19Map tags to IDs using only [[:alnum:]-._]June McEnroe
2021-01-19Don't use a pager if reading standard inputJune McEnroe
2021-01-19Support BSD make syntax and match *.amJune McEnroe
2021-01-19Match tab following escaped newline in make assignmentsJune McEnroe
2021-01-18Allow matching lexers using first input lineJune McEnroe