Cleanly handle select() returning EINTR.
[buftee] / buftee.c
index 0ab9bd4..c31ba69 100644 (file)
--- 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) {
 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);
   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");
     err(1, "select() failed");
+  }
   if (!FD_ISSET(fd, &read_fds))
     errx(1, "select() did not return readable fd = %d", fd);
 }
   if (!FD_ISSET(fd, &read_fds))
     errx(1, "select() did not return readable fd = %d", fd);
 }