summaryrefslogtreecommitdiff
path: root/nscd/nscd_getai.c
diff options
context:
space:
mode:
Diffstat (limited to 'nscd/nscd_getai.c')
-rw-r--r--nscd/nscd_getai.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/nscd/nscd_getai.c b/nscd/nscd_getai.c
index a9eac48ac8..a683976d87 100644
--- a/nscd/nscd_getai.c
+++ b/nscd/nscd_getai.c
@@ -23,7 +23,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <sys/mman.h>
#include <not-cancel.h>
#include "nscd-client.h"
@@ -40,7 +39,6 @@ libc_locked_map_ptr (map_handle);
handling. */
libc_freeres_fn (ai_map_free)
{
-
if (map_handle.mapped != NO_MAPPING)
free (map_handle.mapped);
}
@@ -50,19 +48,21 @@ int
__nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop)
{
size_t keylen = strlen (key) + 1;
+ 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 (GETFDHST, "hosts", &map_handle, &gc_cycle);
+
+ retry:;
const ai_response_header *ai_resp = NULL;
struct nscd_ai_result *resultbuf = NULL;
const char *recend = (const char *) ~UINTMAX_C (0);
char *respdata = NULL;
int retval = -1;
int sock = -1;
- int gc_cycle;
- /* If the mapping is available, try to search there instead of
- communicating with the nscd. */
- struct mapped_database *mapped = __nscd_get_map_ref (GETFDHST, "hosts",
- &map_handle, &gc_cycle);
- retry:
if (mapped != NO_MAPPING)
{
const struct datahead *found = __nscd_cache_search (GETAI, key, keylen,
@@ -131,6 +131,11 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop)
retval = 0;
*result = resultbuf;
}
+ else
+ {
+ free (resultbuf);
+ *h_errnop = NETDB_INTERNAL;
+ }
}
else
{
@@ -155,11 +160,22 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop)
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;
}