mirror of
https://sourceware.org/git/glibc.git
synced 2025-10-23 02:12:24 +03:00
* nscd/nscd_helper.c (get_mapping): Avoid the pread call, just go
ahead and map the file. This should always be correct and we can catch problems later.
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
2007-08-28 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* nscd/nscd_helper.c (get_mapping): Avoid the pread call, just go
|
||||||
|
ahead and map the file. This should always be correct and we can
|
||||||
|
catch problems later.
|
||||||
|
|
||||||
2007-08-28 Jakub Jelinek <jakub@redhat.com>
|
2007-08-28 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
* libio/bits/stdio2.h (__fread_chk, __fread_unlocked_chk): New
|
* libio/bits/stdio2.h (__fread_chk, __fread_unlocked_chk): New
|
||||||
|
|||||||
@@ -286,45 +286,44 @@ get_mapping (request_type type, const char *key,
|
|||||||
|| __builtin_expect (st.st_size < sizeof (struct database_pers_head), 0))
|
|| __builtin_expect (st.st_size < sizeof (struct database_pers_head), 0))
|
||||||
goto out_close;
|
goto out_close;
|
||||||
|
|
||||||
struct database_pers_head head;
|
|
||||||
if (__builtin_expect (TEMP_FAILURE_RETRY (__pread (mapfd, &head,
|
|
||||||
sizeof (head), 0))
|
|
||||||
!= sizeof (head), 0))
|
|
||||||
goto out_close;
|
|
||||||
|
|
||||||
if (__builtin_expect (head.version != DB_VERSION, 0)
|
|
||||||
|| __builtin_expect (head.header_size != sizeof (head), 0)
|
|
||||||
/* This really should not happen but who knows, maybe the update
|
|
||||||
thread got stuck. */
|
|
||||||
|| __builtin_expect (! head.nscd_certainly_running
|
|
||||||
&& head.timestamp + MAPPING_TIMEOUT < time (NULL),
|
|
||||||
0))
|
|
||||||
goto out_close;
|
|
||||||
|
|
||||||
size_t size = (sizeof (head) + roundup (head.module * sizeof (ref_t), ALIGN)
|
|
||||||
+ head.data_size);
|
|
||||||
|
|
||||||
if (__builtin_expect (st.st_size < size, 0))
|
|
||||||
goto out_close;
|
|
||||||
|
|
||||||
/* The file is large enough, map it now. */
|
/* The file is large enough, map it now. */
|
||||||
void *mapping = __mmap (NULL, size, PROT_READ, MAP_SHARED, mapfd, 0);
|
void *mapping = __mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, mapfd, 0);
|
||||||
if (__builtin_expect (mapping != MAP_FAILED, 1))
|
if (__builtin_expect (mapping != MAP_FAILED, 1))
|
||||||
{
|
{
|
||||||
/* Allocate a record for the mapping. */
|
/* Check whether the database is correct and up-to-date. */
|
||||||
struct mapped_database *newp = malloc (sizeof (*newp));
|
struct database_pers_head *head = mapping;
|
||||||
if (newp == NULL)
|
|
||||||
|
if (__builtin_expect (head->version != DB_VERSION, 0)
|
||||||
|
|| __builtin_expect (head->header_size != sizeof (*head), 0)
|
||||||
|
/* This really should not happen but who knows, maybe the update
|
||||||
|
thread got stuck. */
|
||||||
|
|| __builtin_expect (! head->nscd_certainly_running
|
||||||
|
&& (head->timestamp + MAPPING_TIMEOUT
|
||||||
|
< time (NULL)), 0))
|
||||||
{
|
{
|
||||||
/* Ugh, after all we went through the memory allocation failed. */
|
out_unmap:
|
||||||
__munmap (mapping, size);
|
__munmap (mapping, st.st_size);
|
||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t size = (sizeof (*head) + roundup (head->module * sizeof (ref_t),
|
||||||
|
ALIGN)
|
||||||
|
+ head->data_size);
|
||||||
|
|
||||||
|
if (__builtin_expect (st.st_size < size, 0))
|
||||||
|
goto out_unmap;
|
||||||
|
|
||||||
|
/* Allocate a record for the mapping. */
|
||||||
|
struct mapped_database *newp = malloc (sizeof (*newp));
|
||||||
|
if (newp == NULL)
|
||||||
|
/* Ugh, after all we went through the memory allocation failed. */
|
||||||
|
goto out_unmap;
|
||||||
|
|
||||||
newp->head = mapping;
|
newp->head = mapping;
|
||||||
newp->data = ((char *) mapping + head.header_size
|
newp->data = ((char *) mapping + head->header_size
|
||||||
+ roundup (head.module * sizeof (ref_t), ALIGN));
|
+ roundup (head->module * sizeof (ref_t), ALIGN));
|
||||||
newp->mapsize = size;
|
newp->mapsize = size;
|
||||||
newp->datasize = head.data_size;
|
newp->datasize = head->data_size;
|
||||||
/* Set counter to 1 to show it is usable. */
|
/* Set counter to 1 to show it is usable. */
|
||||||
newp->counter = 1;
|
newp->counter = 1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user