]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1732] ntpd ties up CPU on disconnected USB device.
authorDave Hart <hart@ntp.org>
Tue, 7 Dec 2010 08:42:46 +0000 (08:42 +0000)
committerDave Hart <hart@ntp.org>
Tue, 7 Dec 2010 08:42:46 +0000 (08:42 +0000)
bk: 4cfdf386UdHCYZjSIh-qifB9n8eYEA

ChangeLog
ntpd/ntp_io.c

index c97de3e98bfcbc062e2459a12976aa5ebff5c4e6..d12b08dd52665385b7223a821a87bbf629f8ab27 100644 (file)
--- 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 <stenn@ntp.org>
 * [Bug 1738] Windows ntpd has wrong net adapter name.
 * [Bug 1740] ntpdc -c reslist packet count wrongly treated as signed.
index 4b7cad12c74f040e6ebf3d6db74959b2fc58efb7..00951e0bf95d7b3a1f8792483726cc58e7acd7a0 100644 (file)
@@ -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;
        }