]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix other instances of code that looked for HAVE_POLL - poll() is always available.
authorMichael R Sweet <msweet@msweet.org>
Fri, 8 Sep 2023 18:22:43 +0000 (14:22 -0400)
committerMichael R Sweet <msweet@msweet.org>
Fri, 8 Sep 2023 18:22:43 +0000 (14:22 -0400)
cups/dest.c
cups/http-addrlist.c
cups/http.c
cups/sidechannel.c
cups/snmp.c
scheduler/main.c
scheduler/select.c

index 82cbbe0041c5412ca0183ec752231d0cb1eaf226..72f0b8e2c69deb485074fc8e36046a382f6065d9 100644 (file)
@@ -21,9 +21,9 @@
 #  include <notify.h>
 #endif /* HAVE_NOTIFY_H */
 
-#ifdef HAVE_POLL
+#ifndef _WIN32
 #  include <poll.h>
-#endif /* HAVE_POLL */
+#endif /* !_WIN32 */
 
 #ifdef HAVE_MDNSRESPONDER
 #  include <dns_sd.h>
@@ -3410,12 +3410,7 @@ cups_enum_dests(
                 main_fd;                /* File descriptor for lookups */
   DNSServiceRef ipp_ref = NULL;                /* IPP browser */
   DNSServiceRef ipps_ref = NULL;       /* IPPS browser */
-#    ifdef HAVE_POLL
   struct pollfd pfd;                    /* Polling data */
-#    else
-  fd_set        input;                  /* Input set for select() */
-  struct timeval timeout;               /* Timeout for select() */
-#    endif /* HAVE_POLL */
 #  else /* HAVE_AVAHI */
   int           error;                  /* Error value */
   AvahiServiceBrowser *ipp_ref = NULL;  /* IPP browser */
@@ -3732,22 +3727,11 @@ cups_enum_dests(
     cups_elapsed(&curtime);
 
 #  ifdef HAVE_MDNSRESPONDER
-#    ifdef HAVE_POLL
     pfd.fd     = main_fd;
     pfd.events = POLLIN;
 
     nfds = poll(&pfd, 1, remaining > _CUPS_DNSSD_MAXTIME ? _CUPS_DNSSD_MAXTIME : remaining);
 
-#    else
-    FD_ZERO(&input);
-    FD_SET(main_fd, &input);
-
-    timeout.tv_sec  = 0;
-    timeout.tv_usec = 1000 * (remaining > _CUPS_DNSSD_MAXTIME ? _CUPS_DNSSD_MAXTIME : remaining);
-
-    nfds = select(main_fd + 1, &input, NULL, NULL, &timeout);
-#    endif /* HAVE_POLL */
-
     if (nfds > 0)
       DNSServiceProcessResult(data.main_ref);
     else if (nfds < 0 && errno != EINTR && errno != EAGAIN)
index 0dd7fa42a845e29a87b7b06ac1d14b89e36561e3..81adfbcbf6138eda1356a1c64c039961d6f76b46 100644 (file)
 #ifdef HAVE_RESOLV_H
 #  include <resolv.h>
 #endif /* HAVE_RESOLV_H */
-#ifdef HAVE_POLL
-#  include <poll.h>
-#endif /* HAVE_POLL */
 #ifndef _WIN32
+#  include <poll.h>
 #  include <fcntl.h>
 #endif /* _WIN32 */
 
@@ -67,18 +65,9 @@ httpAddrConnect2(
   int                  nfds,           /* Number of file descriptors */
                        fds[100];       /* Socket file descriptors */
   http_addrlist_t      *addrs[100];    /* Addresses */
-#ifndef HAVE_POLL
   int                  max_fd = -1;    /* Highest file descriptor */
-#endif /* !HAVE_POLL */
 #ifdef O_NONBLOCK
-#  ifdef HAVE_POLL
   struct pollfd                pfds[100];      /* Polled file descriptors */
-#  else
-  fd_set               input_set,      /* select() input set */
-                       output_set,     /* select() output set */
-                       error_set;      /* select() error set */
-  struct timeval       timeout;        /* Timeout */
-#  endif /* HAVE_POLL */
 #endif /* O_NONBLOCK */
 #ifdef DEBUG
 #  ifndef _WIN32
@@ -230,10 +219,8 @@ httpAddrConnect2(
       fcntl(fds[nfds], F_SETFL, flags);
 #endif /* !_WIN32 */
 
-#ifndef HAVE_POLL
       if (fds[nfds] > max_fd)
        max_fd = fds[nfds];
-#endif /* !HAVE_POLL */
 
       addrs[nfds] = addrlist;
       nfds ++;
@@ -278,7 +265,6 @@ httpAddrConnect2(
        return (NULL);
       }
 
-#  ifdef HAVE_POLL
       for (i = 0; i < nfds; i ++)
       {
        pfds[i].fd     = fds[i];
@@ -288,21 +274,6 @@ httpAddrConnect2(
       result = poll(pfds, (nfds_t)nfds, addrlist ? 100 : remaining > 250 ? 250 : remaining);
 
       DEBUG_printf("1httpAddrConnect2: poll() returned %d (%d)", result, errno);
-
-#  else
-      FD_ZERO(&input_set);
-      for (i = 0; i < nfds; i ++)
-       FD_SET(fds[i], &input_set);
-      output_set = input_set;
-      error_set  = input_set;
-
-      timeout.tv_sec  = 0;
-      timeout.tv_usec = (addrlist ? 100 : remaining > 250 ? 250 : remaining) * 1000;
-
-      result = select(max_fd + 1, &input_set, &output_set, &error_set, &timeout);
-
-      DEBUG_printf("1httpAddrConnect2: select() returned %d (%d)", result, errno);
-#  endif /* HAVE_POLL */
     }
 #  ifdef _WIN32
     while (result < 0 && (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEWOULDBLOCK));
@@ -316,12 +287,8 @@ httpAddrConnect2(
 
       for (i = 0; i < nfds; i ++)
       {
-#  ifdef HAVE_POLL
        DEBUG_printf("pfds[%d].revents=%x\n", i, pfds[i].revents);
        if (pfds[i].revents && !(pfds[i].revents & (POLLERR | POLLHUP)))
-#  else
-       if (FD_ISSET(fds[i], &input_set) && !FD_ISSET(fds[i], &error_set))
-#  endif /* HAVE_POLL */
        {
          *sock    = fds[i];
          connaddr = addrs[i];
@@ -334,11 +301,7 @@ httpAddrConnect2(
 
           break;
        }
-#  ifdef HAVE_POLL
        else if (pfds[i].revents & (POLLERR | POLLHUP))
-#  else
-       else if (FD_ISSET(fds[i], &error_set))
-#  endif /* HAVE_POLL */
         {
 #  ifdef __sun
           // Solaris incorrectly returns errors when you poll() a socket that is
index cde5f09b1a302df758c1c5fd36cb72222bab523f..0058db5dfe2aca546f5a5270ea296bc4243eee61 100644 (file)
@@ -2754,12 +2754,7 @@ _httpWait(http_t *http,                  // I - HTTP connection
           int    msec,                 // I - Milliseconds to wait
          int    usessl)                // I - Use TLS context?
 {
-#ifdef HAVE_POLL
   struct pollfd                pfd;            // Polled file descriptor
-#else
-  fd_set               input_set;      // select() input set
-  struct timeval       timeout;        // Timeout
-#endif // HAVE_POLL
   int                  nfds;           // Result from select()/poll()
 
 
@@ -2779,7 +2774,6 @@ _httpWait(http_t *http,                   // I - HTTP connection
   }
 
   // Then try doing a select() or poll() to poll the socket...
-#ifdef HAVE_POLL
   pfd.fd     = http->fd;
   pfd.events = POLLIN;
 
@@ -2787,34 +2781,11 @@ _httpWait(http_t *http,                 // I - HTTP connection
   {
     nfds = poll(&pfd, 1, msec);
   }
-  while (nfds < 0 && (errno == EINTR || errno == EAGAIN));
-
-#else
-  do
-  {
-    FD_ZERO(&input_set);
-    FD_SET(http->fd, &input_set);
-
-    DEBUG_printf("6_httpWait: msec=%d, http->fd=%d", msec, http->fd);
-
-    if (msec >= 0)
-    {
-      timeout.tv_sec  = msec / 1000;
-      timeout.tv_usec = (msec % 1000) * 1000;
-
-      nfds = select(http->fd + 1, &input_set, NULL, NULL, &timeout);
-    }
-    else
-      nfds = select(http->fd + 1, &input_set, NULL, NULL, NULL);
-
-    DEBUG_printf("6_httpWait: select() returned %d...", nfds);
-  }
-#  ifdef _WIN32
+#ifdef _WIN32
   while (nfds < 0 && (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEWOULDBLOCK));
-#  else
+#else
   while (nfds < 0 && (errno == EINTR || errno == EAGAIN));
-#  endif // _WIN32
-#endif // HAVE_POLL
+#endif // _WIN32
 
   DEBUG_printf("5_httpWait: returning with nfds=%d, errno=%d...", nfds, errno);
 
@@ -4276,40 +4247,23 @@ http_write(http_t     *http,            // I - HTTP connection
 
     if (http->timeout_value > 0.0)
     {
-#ifdef HAVE_POLL
       struct pollfd    pfd;            // Polled file descriptor
-#else
-      fd_set           output_set;     // Output ready for write?
-      struct timeval   timeout;        // Timeout value
-#endif // HAVE_POLL
       int              nfds;           // Result from select()/poll()
 
       do
       {
-#ifdef HAVE_POLL
        pfd.fd     = http->fd;
        pfd.events = POLLOUT;
 
-       while ((nfds = poll(&pfd, 1, http->wait_value)) < 0 && (errno == EINTR || errno == EAGAIN))
-         // Repeat as needed...
-
-#else
-       do
-       {
-         FD_ZERO(&output_set);
-         FD_SET(http->fd, &output_set);
-
-         timeout.tv_sec  = http->wait_value / 1000;
-         timeout.tv_usec = 1000 * (http->wait_value % 1000);
-
-         nfds = select(http->fd + 1, NULL, &output_set, NULL, &timeout);
-       }
+        do
+        {
+          nfds = poll(&pfd, 1, http->wait_value);
+        }
 #  ifdef _WIN32
        while (nfds < 0 && (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEWOULDBLOCK));
 #  else
        while (nfds < 0 && (errno == EINTR || errno == EAGAIN));
 #  endif // _WIN32
-#endif // HAVE_POLL
 
         if (nfds < 0)
        {
index 10b8a5c9cf58799e788ee6defaca4cb1f876d6f8..e180f716d04cdd810a19bc50c4d570e3ee4f8040 100644 (file)
 #  include <unistd.h>
 #  include <sys/select.h>
 #  include <sys/time.h>
-#endif /* _WIN32 */
-#ifdef HAVE_POLL
 #  include <poll.h>
-#endif /* HAVE_POLL */
+#endif /* _WIN32 */
 
 
 /*
@@ -102,12 +100,7 @@ cupsSideChannelRead(
   ssize_t      bytes;                  /* Bytes read */
   int          templen;                /* Data length from message */
   int          nfds;                   /* Number of file descriptors */
-#ifdef HAVE_POLL
   struct pollfd        pfd;                    /* Poll structure for poll() */
-#else /* select() */
-  fd_set       input_set;              /* Input set for select() */
-  struct timeval stimeout;             /* Timeout value for select() */
-#endif /* HAVE_POLL */
 
 
   DEBUG_printf("cupsSideChannelRead(command=%p, status=%p, data=%p, datalen=%p(%d), timeout=%.3f)", command, status, data, datalen, datalen ? *datalen : -1, timeout);
@@ -123,28 +116,14 @@ cupsSideChannelRead(
   * See if we have pending data on the side-channel socket...
   */
 
-#ifdef HAVE_POLL
   pfd.fd     = CUPS_SC_FD;
   pfd.events = POLLIN;
 
-  while ((nfds = poll(&pfd, 1,
-                     timeout < 0.0 ? -1 : (int)(timeout * 1000))) < 0 &&
-        (errno == EINTR || errno == EAGAIN))
-    ;
-
-#else /* select() */
-  FD_ZERO(&input_set);
-  FD_SET(CUPS_SC_FD, &input_set);
-
-  stimeout.tv_sec  = (int)timeout;
-  stimeout.tv_usec = (int)(timeout * 1000000) % 1000000;
-
-  while ((nfds = select(CUPS_SC_FD + 1, &input_set, NULL, NULL,
-                       timeout < 0.0 ? NULL : &stimeout)) < 0 &&
-        (errno == EINTR || errno == EAGAIN))
-    ;
-
-#endif /* HAVE_POLL */
+  do
+  {
+    nfds = poll(&pfd, 1, timeout < 0.0 ? -1 : (int)(timeout * 1000));
+  }
+  while (nfds < 0 && (errno == EINTR || errno == EAGAIN));
 
   if (nfds < 1)
   {
@@ -520,12 +499,7 @@ cupsSideChannelWrite(
 {
   char         *buffer;                /* Message buffer */
   ssize_t      bytes;                  /* Bytes written */
-#ifdef HAVE_POLL
   struct pollfd        pfd;                    /* Poll structure for poll() */
-#else /* select() */
-  fd_set       output_set;             /* Output set for select() */
-  struct timeval stimeout;             /* Timeout value for select() */
-#endif /* HAVE_POLL */
 
 
  /*
@@ -540,7 +514,6 @@ cupsSideChannelWrite(
   * See if we can safely write to the side-channel socket...
   */
 
-#ifdef HAVE_POLL
   pfd.fd     = CUPS_SC_FD;
   pfd.events = POLLOUT;
 
@@ -552,25 +525,6 @@ cupsSideChannelWrite(
   else if (poll(&pfd, 1, (int)(timeout * 1000)) < 1)
     return (-1);
 
-#else /* select() */
-  FD_ZERO(&output_set);
-  FD_SET(CUPS_SC_FD, &output_set);
-
-  if (timeout < 0.0)
-  {
-    if (select(CUPS_SC_FD + 1, NULL, &output_set, NULL, NULL) < 1)
-      return (-1);
-  }
-  else
-  {
-    stimeout.tv_sec  = (int)timeout;
-    stimeout.tv_usec = (int)(timeout * 1000000) % 1000000;
-
-    if (select(CUPS_SC_FD + 1, NULL, &output_set, NULL, &stimeout) < 1)
-      return (-1);
-  }
-#endif /* HAVE_POLL */
-
  /*
   * Write a side-channel message in the format:
   *
index e81579debae60a173fdb34acb5ffc967daf66cf8..71bde4adedf9feb7f255167f47d9c7ac7a9bcaeb 100644 (file)
@@ -15,9 +15,9 @@
 
 #include "cups-private.h"
 #include "snmp-private.h"
-#ifdef HAVE_POLL
+#ifndef _WIN32
 #  include <poll.h>
-#endif /* HAVE_POLL */
+#endif /* !_WIN32 */
 
 
 /*
@@ -365,35 +365,20 @@ _cupsSNMPRead(int         fd,             /* I - SNMP socket file descriptor */
   if (timeout >= 0.0)
   {
     int                        ready;          /* Data ready on socket? */
-#ifdef HAVE_POLL
     struct pollfd      pfd;            /* Polled file descriptor */
 
     pfd.fd     = fd;
     pfd.events = POLLIN;
 
-    while ((ready = poll(&pfd, 1, (int)(timeout * 1000.0))) < 0 &&
-           (errno == EINTR || errno == EAGAIN));
-
-#else
-    fd_set             input_set;      /* select() input set */
-    struct timeval     stimeout;       /* select() timeout */
-
     do
     {
-      FD_ZERO(&input_set);
-      FD_SET(fd, &input_set);
-
-      stimeout.tv_sec  = (int)timeout;
-      stimeout.tv_usec = (int)((timeout - stimeout.tv_sec) * 1000000);
-
-      ready = select(fd + 1, &input_set, NULL, NULL, &stimeout);
+      ready = poll(&pfd, 1, (int)(timeout * 1000.0));
     }
-#  ifdef _WIN32
-    while (ready < 0 && WSAGetLastError() == WSAEINTR);
-#  else
+#ifdef _WIN32
+    while (ready < 0 && (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEAGAIN));
+#else
     while (ready < 0 && (errno == EINTR || errno == EAGAIN));
-#  endif /* _WIN32 */
-#endif /* HAVE_POLL */
+#endif /* _WIN32 */
 
    /*
     * If we don't have any data ready, return right away...
index d94cf310839e2c8dece88e425c86c5717889997b..12bade0f9ece181b03b9388a88adfb09458a46bb 100644 (file)
@@ -508,11 +508,6 @@ main(int  argc,                            /* I - Number of command-line args */
 
   getrlimit(RLIMIT_NOFILE, &limit);
 
-#if !defined(HAVE_POLL) && !defined(HAVE_EPOLL) && !defined(HAVE_KQUEUE)
-  if (limit.rlim_max > FD_SETSIZE)
-    MaxFDs = FD_SETSIZE;
-  else
-#endif /* !HAVE_POLL && !HAVE_EPOLL && !HAVE_KQUEUE */
 #ifdef RLIM_INFINITY
   if (limit.rlim_max == RLIM_INFINITY)
     MaxFDs = 16384;
index a87985aaa23a638610c7e638d3ecb5d5fbd1cbbf..5c085944a865dd3973439c9f317722b89fbf4412 100644 (file)
@@ -301,6 +301,8 @@ cupsdDoSelect(long timeout)         // I - Timeout in seconds
   else
     nfds = poll(cupsd_pollfds, (nfds_t)count, -1);
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "poll(nfds=%d, timeout=%ld) returned %d", count, timeout < 86400 ? timeout * 1000 : -1, nfds);
+
   if (nfds > 0)
   {
     // Do callbacks for each file descriptor...
@@ -310,7 +312,12 @@ cupsdDoSelect(long timeout)                // I - Timeout in seconds
         continue;
 
       if ((fdptr = find_fd(pfd->fd)) == NULL)
+      {
+        cupsdLogMessage(CUPSD_LOG_DEBUG, "cups_pollfds[%d] not found", pfd->fd);
         continue;
+      }
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "cups_pollfds[%d].revents=%d", pfd->fd, pfd->revents);
 
       retain_fd(fdptr);