From e2452f3bd05521b247162e3a9abdc4e9a79d9ffc Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 6 Jan 2017 19:29:06 +0000 Subject: [PATCH] Add some missing checks for EINTR after select(2). I noticed today that Unix Plink responds to SIGWINCH by accidentally dying of EINTR having interrupted its main select loop, and when I checked, there turn out to be a couple of other select loops with the same bug. --- unix/uxcons.c | 4 +++- unix/uxplink.c | 3 +++ unix/uxsftp.c | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/unix/uxcons.c b/unix/uxcons.c index 641c4b0f..716f3fc5 100644 --- a/unix/uxcons.c +++ b/unix/uxcons.c @@ -101,7 +101,9 @@ static int block_and_read(int fd, void *buf, size_t len) fd_set rfds; FD_ZERO(&rfds); FD_SET(fd, &rfds); - ret = select(fd+1, &rfds, NULL, NULL, NULL); + do { + ret = select(fd+1, &rfds, NULL, NULL, NULL); + } while (ret < 0 && errno == EINTR); assert(ret != 0); if (ret < 0) return ret; diff --git a/unix/uxplink.c b/unix/uxplink.c index c59238a2..82693ba8 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -1122,6 +1122,9 @@ int main(int argc, char **argv) ret = select(maxfd, &rset, &wset, &xset, NULL); } + if (ret < 0 && errno == EINTR) + continue; + if (ret < 0) { perror("select"); exit(1); diff --git a/unix/uxsftp.c b/unix/uxsftp.c index 6e394910..a9fb9cb3 100644 --- a/unix/uxsftp.c +++ b/unix/uxsftp.c @@ -531,7 +531,9 @@ static int ssh_sftp_do_select(int include_stdin, int no_fds_ok) now = GETTICKCOUNT(); } while (ret < 0 && errno == EINTR); } else { - ret = select(maxfd, &rset, &wset, &xset, NULL); + do { + ret = select(maxfd, &rset, &wset, &xset, NULL); + } while (ret < 0 && errno == EINTR); } } while (ret == 0); -- 2.45.2