From 4b7c0d634e02224d587a66ae240aba9e47a386c8 Mon Sep 17 00:00:00 2001 From: Emil Mikulic Date: Mon, 11 Mar 2013 04:23:34 +1100 Subject: [PATCH] Cleanly handle select() returning EINTR. This is usually the result of catching SIGTERM (via ^C). After this change, we exit cleanly. --- buftee.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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); } -- 2.17.1