From: Dave Hart Date: Tue, 7 Dec 2010 08:42:46 +0000 (+0000) Subject: [Bug 1732] ntpd ties up CPU on disconnected USB device. X-Git-Tag: NTP_4_2_7P91~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ea3cbafff8d9ef2b999c59fff49c1418ab5e111;p=thirdparty%2Fntp.git [Bug 1732] ntpd ties up CPU on disconnected USB device. bk: 4cfdf386UdHCYZjSIh-qifB9n8eYEA --- diff --git a/ChangeLog b/ChangeLog index c97de3e98..d12b08dd5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* [Bug 1732] ntpd ties up CPU on disconnected USB device. (4.2.7p90) 2010/12/06 Released by Harlan Stenn * [Bug 1738] Windows ntpd has wrong net adapter name. * [Bug 1740] ntpdc -c reslist packet count wrongly treated as signed. diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 4b7cad12c..00951e0bf 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -3492,6 +3492,7 @@ input_handler( */ if (n < 0) { int err = errno; + int j, b, prior; /* * extended FAU debugging output */ @@ -3500,15 +3501,21 @@ input_handler( "select(%d, %s, 0L, 0L, &0.0) error: %m", maxactivefd + 1, fdbits(maxactivefd, &activefds)); - if (err == EBADF) { - int j, b; - fds = activefds; - for (j = 0; j <= maxactivefd; j++) - if ((FD_ISSET(j, &fds) - && (read(j, &b, 0) == -1))) - msyslog(LOG_ERR, - "Bad file descriptor %d", - j); + if (err != EBADF) + return; + for (j = 0, prior = 0; j <= maxactivefd; j++) { + if (FD_ISSET(j, &activefds)) { + if (-1 != read(j, &b, 0)) { + prior = j; + continue; + } + msyslog(LOG_ERR, + "Removing bad file descriptor %d from select set", + j); + FD_CLR(j, &activefds); + if (j == maxactivefd) + maxactivefd = prior; + } } return; }