=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/ssh-keyscan.c,v retrieving revision 1.140 retrieving revision 1.141 diff -u -r1.140 -r1.141 --- src/usr.bin/ssh/ssh-keyscan.c 2021/10/02 03:17:01 1.140 +++ src/usr.bin/ssh/ssh-keyscan.c 2021/11/11 15:32:32 1.141 @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-keyscan.c,v 1.140 2021/10/02 03:17:01 dtucker Exp $ */ +/* $OpenBSD: ssh-keyscan.c,v 1.141 2021/11/11 15:32:32 deraadt Exp $ */ /* * Copyright 1995, 1996 by David Mazieres . * @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -79,8 +80,7 @@ #define MAXCON (maxfd - 10) extern char *__progname; -fd_set *read_wait; -size_t read_wait_nfdset; +struct pollfd *read_wait; int ncon; /* @@ -105,7 +105,7 @@ char *c_output_name; /* Hostname of connection for output */ char *c_data; /* Data read from this fd */ struct ssh *c_ssh; /* SSH-connection */ - struct timeval c_tv; /* Time at which connection gets aborted */ + struct timespec c_ts; /* Time at which connection gets aborted */ TAILQ_ENTRY(Connection) c_link; /* List of connections in timeout order. */ } con; @@ -395,10 +395,11 @@ fdcon[s].c_len = 4; fdcon[s].c_off = 0; fdcon[s].c_keytype = keytype; - monotime_tv(&fdcon[s].c_tv); - fdcon[s].c_tv.tv_sec += timeout; + monotime_ts(&fdcon[s].c_ts); + fdcon[s].c_ts.tv_sec += timeout; TAILQ_INSERT_TAIL(&tq, &fdcon[s], c_link); - FD_SET(s, read_wait); + read_wait[s].fd = s; + read_wait[s].events = POLLIN; ncon++; return (s); } @@ -421,7 +422,8 @@ } else close(s); TAILQ_REMOVE(&tq, &fdcon[s], c_link); - FD_CLR(s, read_wait); + read_wait[s].fd = -1; + read_wait[s].events = 0; ncon--; } @@ -429,8 +431,8 @@ contouch(int s) { TAILQ_REMOVE(&tq, &fdcon[s], c_link); - monotime_tv(&fdcon[s].c_tv); - fdcon[s].c_tv.tv_sec += timeout; + monotime_ts(&fdcon[s].c_ts); + fdcon[s].c_ts.tv_sec += timeout; TAILQ_INSERT_TAIL(&tq, &fdcon[s], c_link); } @@ -558,40 +560,31 @@ static void conloop(void) { - struct timeval seltime, now; - fd_set *r, *e; + struct timespec seltime, now; con *c; int i; - monotime_tv(&now); + monotime_ts(&now); c = TAILQ_FIRST(&tq); - if (c && timercmp(&c->c_tv, &now, >)) - timersub(&c->c_tv, &now, &seltime); + if (c && timespeccmp(&c->c_ts, &now, >)) + timespecsub(&c->c_ts, &now, &seltime); else - timerclear(&seltime); + timespecclear(&seltime); - r = xcalloc(read_wait_nfdset, sizeof(fd_mask)); - e = xcalloc(read_wait_nfdset, sizeof(fd_mask)); - memcpy(r, read_wait, read_wait_nfdset * sizeof(fd_mask)); - memcpy(e, read_wait, read_wait_nfdset * sizeof(fd_mask)); - - while (select(maxfd, r, NULL, e, &seltime) == -1 && + while (ppoll(read_wait, maxfd, &seltime, NULL) == -1 && (errno == EAGAIN || errno == EINTR)) ; for (i = 0; i < maxfd; i++) { - if (FD_ISSET(i, e)) { - error("%s: exception!", fdcon[i].c_name); + if (read_wait[i].revents & (POLLHUP|POLLERR|POLLNVAL)) confree(i); - } else if (FD_ISSET(i, r)) + else if (read_wait[i].revents & POLLIN) conread(i); } - free(r); - free(e); c = TAILQ_FIRST(&tq); - while (c && timercmp(&c->c_tv, &now, <)) { + while (c && timespeccmp(&c->c_ts, &now, <)) { int s = c->c_fd; c = TAILQ_NEXT(c, c_link); @@ -759,9 +752,7 @@ if (maxfd > fdlim_get(0)) fdlim_set(maxfd); fdcon = xcalloc(maxfd, sizeof(con)); - - read_wait_nfdset = howmany(maxfd, NFDBITS); - read_wait = xcalloc(read_wait_nfdset, sizeof(fd_mask)); + read_wait = xcalloc(maxfd, sizeof(struct pollfd)); for (j = 0; j < fopt_count; j++) { if (argv[j] == NULL)