Blob Blame History Raw
From 0dd454ac2335714d30e20afeed2259a30e57348e Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Sat, 5 Oct 2013 20:55:11 +0200
Subject: [PATCH] Use a timeout when skipping remaining result data

When the NSS modules closes the connection and skips any remaining
result data, wait for up to 500 msec to read any available data.

See:
https://bugzilla.redhat.com/show_bug.cgi?id=1003011
---
 common/tio.c | 4 ++--
 common/tio.h | 2 +-
 nss/common.h | 8 ++++++--
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/common/tio.c b/common/tio.c
index 9aef80ca91faedad8f75e09b9070d22ed4a0878d..da84673b9174f77e6eb0e287d18b7054deae4491 100644
--- a/common/tio.c
+++ b/common/tio.c
@@ -298,7 +298,7 @@ int tio_skip(TFILE *fp, size_t count)
 }
 
 /* Read all available data from the stream and empty the read buffer. */
-int tio_skipall(TFILE *fp)
+int tio_skipall(TFILE *fp, int skiptimeout)
 {
   struct pollfd fds[1];
   int rv;
@@ -318,7 +318,7 @@ int tio_skipall(TFILE *fp)
     /* see if any data is available */
     fds[0].fd=fp->fd;
     fds[0].events=POLLIN;
-    rv=poll(fds,1,0);
+    rv = poll(fds, 1, skiptimeout);
     /* check the poll() result */
     if (rv==0)
       return 0; /* no file descriptor ready */
diff --git a/common/tio.h b/common/tio.h
index cd3f370732e4c54815187bb8012fd5a5ff8972af..2c64d7096ce0643ff56ebf009fb2950ac80d62b8 100644
--- a/common/tio.h
+++ b/common/tio.h
@@ -59,7 +59,7 @@ int tio_read(TFILE *fp,void *buf,size_t count);
 int tio_skip(TFILE *fp,size_t count);
 
 /* Read all available data from the stream and empty the read buffer. */
-int tio_skipall(TFILE *fp);
+int tio_skipall(TFILE *fp, int skiptimeout);
 
 /* Write the specified buffer to the stream. */
 int tio_write(TFILE *fp,const void *buf,size_t count);
diff --git a/nss/common.h b/nss/common.h
index e8d8e0526499c252f69a558384ddae8504009d26..c9bd7a349b318f78dc35102f5f1cb8b47718581f 100644
--- a/nss/common.h
+++ b/nss/common.h
@@ -35,6 +35,10 @@
 #include "solnss.h"
 #endif /* NSS_FLAVOUR_SOLARIS */
 
+/* skip timeout determines the maximum time to wait when closing the
+   connection and reading whatever data that is available */
+#define SKIP_TIMEOUT 500
+
 /* These are macros for handling read and write problems, they are
    NSS specific due to the return code so are defined here. They
    genrally close the open file, set an error code and return with
@@ -127,7 +131,7 @@
   /* close socket and we're done */ \
   if ((retv==NSS_STATUS_SUCCESS)||(retv==NSS_STATUS_TRYAGAIN)) \
   { \
-    (void)tio_skipall(fp); \
+    (void)tio_skipall(fp, SKIP_TIMEOUT);                                    \
     (void)tio_close(fp); \
   } \
   return retv;
@@ -203,7 +207,7 @@
   NSS_AVAILCHECK; \
   if (fp!=NULL) \
   { \
-    (void)tio_skipall(fp); \
+    (void)tio_skipall(fp, SKIP_TIMEOUT);                                    \
     (void)tio_close(fp); \
     fp=NULL; \
   } \
-- 
1.8.3.1