~ubuntu-branches/ubuntu/precise/eglibc/precise-201308281639

« back to all changes in this revision

Viewing changes to nscd/aicache.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-02-08 01:58:09 UTC
  • mfrom: (1.5.3) (288.1.12 precise)
  • Revision ID: package-import@ubuntu.com-20120208015809-ulscst7uteq3e22z
Tags: 2.15~pre6-0ubuntu10
Merge from Debian (r5151, 2.13-26).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Cache handling for host lookup.
2
 
   Copyright (C) 2004-2008, 2009, 2010 Free Software Foundation, Inc.
 
2
   Copyright (C) 2004-2008, 2009, 2010, 2011 Free Software Foundation, Inc.
3
3
   This file is part of the GNU C Library.
4
4
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
5
5
 
58
58
};
59
59
 
60
60
 
61
 
static void
 
61
static time_t
62
62
addhstaiX (struct database_dyn *db, int fd, request_header *req,
63
63
           void *key, uid_t uid, struct hashentry *const he,
64
64
           struct datahead *dh)
119
119
  ssize_t total = 0;
120
120
  char *key_copy = NULL;
121
121
  bool alloca_used = false;
 
122
  time_t timeout = MAX_TIMEOUT_VALUE;
122
123
 
123
124
  while (!no_more)
124
125
    {
388
389
      dataset->head.usable = true;
389
390
 
390
391
      /* Compute the timeout time.  */
391
 
      dataset->head.timeout = time (NULL) + (ttl == INT32_MAX
392
 
                                             ? db->postimeout : ttl);
 
392
      dataset->head.ttl = ttl == INT32_MAX ? db->postimeout : ttl;
 
393
      timeout = dataset->head.timeout = time (NULL) + dataset->head.ttl;
393
394
 
394
395
      dataset->resp.version = NSCD_VERSION;
395
396
      dataset->resp.found = 1;
421
422
                 timeout value.  Note that the new record has been
422
423
                 allocated on the stack and need not be freed.  */
423
424
              dh->timeout = dataset->head.timeout;
 
425
              dh->ttl = dataset->head.ttl;
424
426
              ++dh->nreloads;
425
427
            }
426
428
          else
459
461
                      <= (sizeof (struct database_pers_head)
460
462
                          + db->head->module * sizeof (ref_t)
461
463
                          + db->head->data_size));
 
464
# ifndef __ASSUME_SENDFILE
462
465
              ssize_t written;
463
 
              written = sendfileall (fd, db->wr_fd, (char *) &dataset->resp
464
 
                                     - (char *) db->head, dataset->head.recsize);
 
466
              written =
 
467
# endif
 
468
                sendfileall (fd, db->wr_fd, (char *) &dataset->resp
 
469
                             - (char *) db->head, dataset->head.recsize);
465
470
# ifndef __ASSUME_SENDFILE
466
471
              if (written == -1 && errno == ENOSYS)
467
472
                goto use_write;
496
501
      if (reload_count != UINT_MAX && dh->nreloads == reload_count)
497
502
        /* Do not reset the value if we never not reload the record.  */
498
503
        dh->nreloads = reload_count - 1;
 
504
 
 
505
      /* Reload with the same time-to-live value.  */
 
506
      timeout = dh->timeout = time (NULL) + dh->ttl;
499
507
    }
500
508
  else
501
509
    {
506
514
      if (fd != -1)
507
515
        TEMP_FAILURE_RETRY (send (fd, &notfound, total, MSG_NOSIGNAL));
508
516
 
509
 
      dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len, 1);
510
517
      /* If we cannot permanently store the result, so be it.  */
511
 
      if (dataset != NULL)
 
518
      if (__builtin_expect (db->negtimeout == 0, 0))
 
519
        {
 
520
          /* Mark the old entry as obsolete.  */
 
521
          if (dh != NULL)
 
522
            dh->usable = false;
 
523
          dataset = NULL;
 
524
        }
 
525
      else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
 
526
                                              + req->key_len), 1)) != NULL)
512
527
        {
513
528
          dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
514
529
          dataset->head.recsize = total;
517
532
          dataset->head.usable = true;
518
533
 
519
534
          /* Compute the timeout time.  */
520
 
          dataset->head.timeout = time (NULL) + db->negtimeout;
 
535
          timeout = dataset->head.timeout = time (NULL) + db->negtimeout;
 
536
          dataset->head.ttl = db->negtimeout;
521
537
 
522
538
          /* This is the reply.  */
523
539
          memcpy (&dataset->resp, &notfound, total);
528
544
   }
529
545
 
530
546
 out:
531
 
  _res.options = old_res_options;
 
547
  _res.options |= old_res_options & RES_USE_INET6;
532
548
 
533
549
  if (dataset != NULL && !alloca_used)
534
550
    {
551
567
      if (dh != NULL)
552
568
        dh->usable = false;
553
569
    }
 
570
 
 
571
  return timeout;
554
572
}
555
573
 
556
574
 
562
580
}
563
581
 
564
582
 
565
 
void
 
583
time_t
566
584
readdhstai (struct database_dyn *db, struct hashentry *he, struct datahead *dh)
567
585
{
568
586
  request_header req =
571
589
      .key_len = he->len
572
590
    };
573
591
 
574
 
  addhstaiX (db, -1, &req, db->data + he->key, he->owner, he, dh);
 
592
  return addhstaiX (db, -1, &req, db->data + he->key, he->owner, he, dh);
575
593
}