]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nscd/aicache.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / nscd / aicache.c
index a3de6368bd956d6921bf596e07c59b26da6f25a0..937cb93203ccc51f4775fe1791f6e7354b627446 100644 (file)
@@ -1,5 +1,5 @@
 /* Cache handling for host lookup.
-   Copyright (C) 2004-2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2004-2015 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
 
@@ -25,6 +25,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <resolv/res_hconf.h>
 
 #include "dbg_log.h"
 #include "nscd.h"
@@ -76,7 +77,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
     char strdata[0];
   } *dataset = NULL;
 
-  if (__builtin_expect (debug_level > 0, 0))
+  if (__glibc_unlikely (debug_level > 0))
     {
       if (he == NULL)
        dbg_log (_("Haven't found \"%s\" in hosts cache!"), (char *) key);
@@ -85,23 +86,25 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
     }
 
   static service_user *hosts_database;
-  service_user *nip = NULL;
+  service_user *nip;
   int no_more;
   int rc6 = 0;
   int rc4 = 0;
   int herrno = 0;
 
-  if (hosts_database != NULL)
-    {
-      nip = hosts_database;
-      no_more = 0;
-    }
-  else
+  if (hosts_database == NULL)
     no_more = __nss_database_lookup ("hosts", NULL,
-                                    "dns [!UNAVAIL=return] files", &nip);
+                                    "dns [!UNAVAIL=return] files",
+                                    &hosts_database);
+  else
+    no_more = 0;
+  nip = hosts_database;
 
+  /* Initialize configurations.  */
+  if (__glibc_unlikely (!_res_hconf.initialized))
+    _res_hconf_init ();
   if (__res_maybe_init (&_res, 0) == -1)
-           no_more = 1;
+    no_more = 1;
 
   /* If we are looking for both IPv4 and IPv6 address we don't want
      the lookup functions to automatically promote IPv4 addresses to
@@ -380,17 +383,12 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
          cp = family;
        }
 
-      /* Fill in the rest of the dataset.  */
-      dataset->head.allocsize = total + req->key_len;
-      dataset->head.recsize = total - offsetof (struct dataset, resp);
-      dataset->head.notfound = false;
-      dataset->head.nreloads = he == NULL ? 0 : (dh->nreloads + 1);
-      dataset->head.usable = true;
-
-      /* Compute the timeout time.  */
-      dataset->head.ttl = ttl == INT32_MAX ? db->postimeout : ttl;
-      timeout = dataset->head.timeout = time (NULL) + dataset->head.ttl;
+      timeout = datahead_init_pos (&dataset->head, total + req->key_len,
+                                  total - offsetof (struct dataset, resp),
+                                  he == NULL ? 0 : dh->nreloads + 1,
+                                  ttl == INT32_MAX ? db->postimeout : ttl);
 
+      /* Fill in the rest of the dataset.  */
       dataset->resp.version = NSCD_VERSION;
       dataset->resp.found = 1;
       dataset->resp.naddrs = naddrs;
@@ -431,7 +429,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
              struct dataset *newp
                = (struct dataset *) mempool_alloc (db, total + req->key_len,
                                                    1);
-             if (__builtin_expect (newp != NULL, 1))
+             if (__glibc_likely (newp != NULL))
                {
                  /* Adjust pointer into the memory block.  */
                  key_copy = (char *) newp + (key_copy - (char *) dataset);
@@ -525,15 +523,9 @@ next_nip:
       else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
                                              + req->key_len), 1)) != NULL)
        {
-         dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
-         dataset->head.recsize = total;
-         dataset->head.notfound = true;
-         dataset->head.nreloads = 0;
-         dataset->head.usable = true;
-
-         /* Compute the timeout time.  */
-         timeout = dataset->head.timeout = time (NULL) + db->negtimeout;
-         dataset->head.ttl = db->negtimeout;
+         timeout = datahead_init_neg (&dataset->head,
+                                      sizeof (struct dataset) + req->key_len,
+                                      total, db->negtimeout);
 
          /* This is the reply.  */
          memcpy (&dataset->resp, &notfound, total);