From: Emil Mikulic Date: Sun, 10 Mar 2013 17:23:34 +0000 (+1100) Subject: Cleanly handle select() returning EINTR. X-Git-Url: https://unix4lyfe.org/gitweb/buftee/commitdiff_plain/4b7c0d634e02224d587a66ae240aba9e47a386c8 Cleanly handle select() returning EINTR. This is usually the result of catching SIGTERM (via ^C). After this change, we exit cleanly. --- diff --git a/buftee.c b/buftee.c index 0ab9bd4..c31ba69 100644 --- a/buftee.c +++ b/buftee.c @@ -245,12 +245,17 @@ static int xwrite(const int fd, struct buf* const buf) { static int max(const int a, const int b) { return (a > b) ? a : b; } static void wait_until_readable(const int fd) { - int select_ret; fd_set read_fds; FD_ZERO(&read_fds); FD_SET(fd, &read_fds); - if ((select_ret = select(fd + 1, &read_fds, NULL, NULL, NULL)) == -1) + int select_ret = select(fd + 1, &read_fds, NULL, NULL, NULL); + if (select_ret == -1) { + if (errno == EINTR) { + assert(stopping); // that should have been SIGTERM + return; + } err(1, "select() failed"); + } if (!FD_ISSET(fd, &read_fds)) errx(1, "select() did not return readable fd = %d", fd); }