aboutsummaryrefslogtreecommitdiff
path: root/nscd/connections.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-08-25 17:24:52 +0000
committerUlrich Drepper <drepper@redhat.com>2004-08-25 17:24:52 +0000
commitd6db09753a9d33d5f5b98d402b01a2b168ac7785 (patch)
treecb637742eee00b837dbd8db1d777061e12ec2998 /nscd/connections.c
parent801ddb6a034c436be7e9ede6865aa2bd39ecfa3c (diff)
downloadglibc-d6db09753a9d33d5f5b98d402b01a2b168ac7785.zip
glibc-d6db09753a9d33d5f5b98d402b01a2b168ac7785.tar.gz
glibc-d6db09753a9d33d5f5b98d402b01a2b168ac7785.tar.bz2
Update.
2004-08-25 Ulrich Drepper <drepper@redhat.com> * nscd/connections.c: Make socket nonblocking so that threads don't get stuck on accept. Fix locking. * nscd/grpcache.c (cache_addgr): Use cope of original key in hash entry with alternative key. * nscd/pwdcache.c (cache_addpw): Likewise.
Diffstat (limited to 'nscd/connections.c')
-rw-r--r--nscd/connections.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/nscd/connections.c b/nscd/connections.c
index f8efcc2..0018ed9 100644
--- a/nscd/connections.c
+++ b/nscd/connections.c
@@ -22,6 +22,7 @@
#include <atomic.h>
#include <error.h>
#include <errno.h>
+#include <fcntl.h>
#include <grp.h>
#include <pthread.h>
#include <pwd.h>
@@ -207,6 +208,12 @@ nscd_init (void)
exit (1);
}
+ /* We don't wait for data otherwise races between threads can get
+ them stuck on accept. */
+ int fl = fcntl (sock, F_GETFL);
+ if (fl != -1)
+ fcntl (sock, F_SETFL, fl | O_NONBLOCK);
+
/* Set permissions for the socket. */
chmod (_PATH_NSCDSOCKET, 0666);
@@ -451,32 +458,37 @@ nscd_run (void *p)
while (1)
{
int nr;
+ time_t now = 0;
/* One more thread available. */
atomic_increment (&nready);
no_conn:
- if (run_prune)
- do
- {
- time_t now = time (NULL);
- int timeout = now < next_prune ? 1000 * (next_prune - now) : 0;
+ do
+ {
+ int timeout = -1;
+ if (run_prune)
+ {
+ now = time (NULL);
+ timeout = now < next_prune ? 1000 * (next_prune - now) : 0;
+ }
- nr = poll (&conn, 1, timeout);
+ nr = poll (&conn, 1, timeout);
- if (nr == 0)
- {
- /* The `poll' call timed out. It's time to clean up the
- cache. */
- atomic_decrement (&nready);
- assert (my_number < lastdb);
- prune_cache (&dbs[my_number], time(NULL));
- now = time (NULL);
- next_prune = now + CACHE_PRUNE_INTERVAL;
- goto try_get;
- }
- }
- while ((conn.revents & POLLRDNORM) == 0);
+ if (nr == 0)
+ {
+ /* The `poll' call timed out. It's time to clean up the
+ cache. */
+ atomic_decrement (&nready);
+ assert (my_number < lastdb);
+ prune_cache (&dbs[my_number], time(NULL));
+ now = time (NULL);
+ next_prune = now + CACHE_PRUNE_INTERVAL;
+ atomic_increment (&nready);
+ goto try_get;
+ }
+ }
+ while ((conn.revents & POLLRDNORM) == 0);
got_data:;
/* We have a new incoming connection. Accept the connection. */
@@ -490,8 +502,9 @@ nscd_run (void *p)
if (__builtin_expect (fd, 0) < 0)
{
- dbg_log (_("while accepting connection: %s"),
- strerror_r (errno, buf, sizeof (buf)));
+ if (errno != EAGAIN && errno != EWOULDBLOCK)
+ dbg_log (_("while accepting connection: %s"),
+ strerror_r (errno, buf, sizeof (buf)));
goto no_conn;
}