]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Replaced select() system call with poll() on POSIX systems
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Thu, 28 Jan 2016 09:45:17 +0000 (10:45 +0100)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Thu, 28 Jan 2016 10:16:40 +0000 (11:16 +0100)
This allows to use the default gnutls functions with file descriptors
over the maximum supported by select.

NEWS
doc/cha-gtls-app.texi
lib/system.c
tests/seccomp.c

diff --git a/NEWS b/NEWS
index e3a824ed844770e9e6378262fcbcaf0cc9b7d3ce..ae9c1a4005eea90c921fc3dbb4603a1ee39e9735 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,8 @@ See the end for copying conditions.
 
 ** libgnutls: Replaced writev() system call with sendmsg().
 
+** libgnutls: Replaced select() system call with poll() on POSIX systems.
+
 ** certtool: Added the --provable option.
 
 ** API and ABI modifications:
index 03a17d6288c9bd513c34e0642ea05e0d7871bf1f..0bfd9fbc0fbd46403856ede564995c6e964402c1 100644 (file)
@@ -261,7 +261,7 @@ operation.
 @item sendmsg
 @item read (to read from /dev/urandom)
 @item getrandom (this is Linux-kernel specific)
-@item select
+@item poll
 @end itemize
 
 As well as any calls needed for memory allocation to work. Note however, that GnuTLS
index f5f9c76ecef1f2ed1e2ac18d5f9c70dff6bcc302..a096cea242b383efa97bb0f2d238cd448c877735 100644 (file)
@@ -45,8 +45,9 @@ static HMODULE Crypt32_dll;
 #  define pCertEnumCRLsInStore CertEnumCRLsInStore
 # endif
 
-#else /* _WIN32 */
-# include <sys/select.h>
+#else /* !_WIN32 */
+
+# include <poll.h>
 
 # ifdef HAVE_PTHREAD_LOCKS
 #  include <pthread.h>
@@ -164,10 +165,24 @@ system_read(gnutls_transport_ptr_t ptr, void *data, size_t data_size)
  **/
 int gnutls_system_recv_timeout(gnutls_transport_ptr_t ptr, unsigned int ms)
 {
-       fd_set rfds;
-       struct timeval _tv, *tv = NULL;
        int ret;
        int fd = GNUTLS_POINTER_TO_INT(ptr);
+#ifndef _WIN32
+       int timeo;
+       struct pollfd pfd;
+
+       pfd.fd = fd;
+       pfd.events = POLLIN;
+       pfd.revents = 0;
+
+       if (ms == GNUTLS_INDEFINITE_TIMEOUT)
+               timeo = -1;
+       else
+               timeo = ms;
+       ret = poll(&pfd, 1, timeo);
+#else
+       fd_set rfds;
+       struct timeval _tv, *tv = NULL;
 
        FD_ZERO(&rfds);
        FD_SET(fd, &rfds);
@@ -179,6 +194,7 @@ int gnutls_system_recv_timeout(gnutls_transport_ptr_t ptr, unsigned int ms)
        }
 
        ret = select(fd + 1, &rfds, NULL, NULL, tv);
+#endif
        if (ret <= 0)
                return ret;
 
@@ -437,7 +453,6 @@ static
 int add_system_trust(gnutls_x509_trust_list_t list, unsigned int tl_flags,
                     unsigned int tl_vflags)
 {
-       char path[GNUTLS_PATH_MAX];
        unsigned int i;
        int r = 0;
 
index 8427fd9f7b6596ced852a4a82bcb2670f7a663ea..f5c0f2a7662b6d88ee8d6046d8fa5cab0e027a71 100644 (file)
@@ -76,9 +76,7 @@ int disable_system_calls(void)
        ADD_SYSCALL(rt_sigprocmask, 0);
 
        /* used in to detect reading timeouts */
-       ADD_SYSCALL(select, 0);
-       /* in x86, glibc uses _newselect() */
-       ADD_SYSCALL(_newselect, 0);
+       ADD_SYSCALL(poll, 0);
 
        /* for memory allocation */
        ADD_SYSCALL(brk, 0);