Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Add some missing checks for EINTR after select(2).
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sgtatham committed Jan 6, 2017
1 parent 86ba2e6 commit e2452f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion unix/uxcons.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions unix/uxplink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion unix/uxsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e2452f3

Please sign in to comment.