about summary refs log tree commit diff
path: root/nscd/nscd_getpw_r.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-09-30 08:08:40 +0000
committerUlrich Drepper <drepper@redhat.com>2004-09-30 08:08:40 +0000
commit0891f9706f4fc0951324b3a3f113f60191b96434 (patch)
tree48a72b0e6dfe0ee3564e3c810dea939b57d1a96a /nscd/nscd_getpw_r.c
parent085f2dd0ad1ba523749669b24f0999a3d1496ed7 (diff)
downloadglibc-0891f9706f4fc0951324b3a3f113f60191b96434.tar.gz
glibc-0891f9706f4fc0951324b3a3f113f60191b96434.tar.xz
glibc-0891f9706f4fc0951324b3a3f113f60191b96434.zip
Update.
2004-09-30  Ulrich Drepper  <drepper@redhat.com>

	* nscd/nscd-client.h (__nscd_get_map_ref): Drop volatile from last
	parameter.
	(__nscd_drop_map_ref): Change second parameter to be a referenc to
	a variable.  Update variable when cycle count changed.
	* nscd/nscd_helper.c (__nscd_get_map_ref): Remove volatile here, too.
	* nscd/nscd_getai.c: Correctly use __nscd_drop_map_ref.  Reinitialize
	all variables and avoid memory leak in case of retries.
	* nscd/nscd_getgr_r.c: Likewise.
	* nscd/nscd_gethst_r.c: Likewise.
	* nscd/nscd_getpw_r.c: Likewise.
	* nscd/nscd_initgroups.c: Likewise.

	* nscd/nscd.h: Add declaretion of addinitgroups and
	readdinitgroups.
Diffstat (limited to 'nscd/nscd_getpw_r.c')
-rw-r--r--nscd/nscd_getpw_r.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/nscd/nscd_getpw_r.c b/nscd/nscd_getpw_r.c
index 0d15a0cc3f..9af3858454 100644
--- a/nscd/nscd_getpw_r.c
+++ b/nscd/nscd_getpw_r.c
@@ -84,17 +84,18 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
 	      struct passwd *resultbuf, char *buffer, size_t buflen,
 	      struct passwd **result)
 {
+  int gc_cycle;
+  /* If the mapping is available, try to search there instead of
+     communicating with the nscd.  */
+  struct mapped_database *mapped;
+  mapped = __nscd_get_map_ref (GETFDPW, "passwd", &map_handle, &gc_cycle);
+
+ retry:;
   const pw_response_header *pw_resp = NULL;
   const char *pw_name = NULL;
   int retval = -1;
-  int gc_cycle;
   const char *recend = (const char *) ~UINTMAX_C (0);
 
-  /* If the mapping is available, try to search there instead of
-     communicating with the nscd.  */
-  struct mapped_database *mapped = __nscd_get_map_ref (GETFDPW, "passwd",
-						       &map_handle, &gc_cycle);
- retry:
   if (mapped != NO_MAPPING)
     {
       const struct datahead *found = __nscd_cache_search (type, key, keylen,
@@ -199,11 +200,22 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
   if (sock != -1)
     close_not_cancel_no_status (sock);
  out:
-  if (__nscd_drop_map_ref (mapped, gc_cycle) != 0)
-    /* When we come here this means there has been a GC cycle while we
-       were looking for the data.  This means the data might have been
-       inconsistent.  Retry.  */
-    goto retry;
+  if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0 && retval != -1)
+    {
+      /* When we come here this means there has been a GC cycle while we
+	 were looking for the data.  This means the data might have been
+	 inconsistent.  Retry if possible.  */
+      if ((gc_cycle & 1) != 0)
+	{
+	  /* nscd is just running gc now.  Disable using the mapping.  */
+	  __nscd_unmap (mapped);
+	  mapped = NO_MAPPING;
+	}
+
+      free (resultbuf);
+
+      goto retry;
+    }
 
   return retval;
 }