mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-22 10:50:07 +00:00
* nscd/connections.c (send_ro_fd): Also transfer file size.
* nscd/nscd_helper.c (get_mapping): If nscd also transfers the file size don't call fstat.
This commit is contained in:
parent
0adfcc0526
commit
f3c54060af
@ -1,5 +1,9 @@
|
||||
2007-08-28 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
* nscd/connections.c (send_ro_fd): Also transfer file size.
|
||||
* nscd/nscd_helper.c (get_mapping): If nscd also transfers the
|
||||
file size don't call fstat.
|
||||
|
||||
* 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.
|
||||
|
@ -907,9 +907,14 @@ send_ro_fd (struct database_dyn *db, char *key, int fd)
|
||||
return;
|
||||
|
||||
/* We need to send some data along with the descriptor. */
|
||||
struct iovec iov[1];
|
||||
uint64_t mapsize = (db->head->data_size
|
||||
+ roundup (db->head->module * sizeof (ref_t), ALIGN)
|
||||
+ sizeof (struct database_pers_head));
|
||||
struct iovec iov[2];
|
||||
iov[0].iov_base = key;
|
||||
iov[0].iov_len = strlen (key) + 1;
|
||||
iov[1].iov_base = &mapsize;
|
||||
iov[1].iov_len = sizeof (mapsize);
|
||||
|
||||
/* Prepare the control message to transfer the descriptor. */
|
||||
union
|
||||
@ -917,7 +922,7 @@ send_ro_fd (struct database_dyn *db, char *key, int fd)
|
||||
struct cmsghdr hdr;
|
||||
char bytes[CMSG_SPACE (sizeof (int))];
|
||||
} buf;
|
||||
struct msghdr msg = { .msg_iov = iov, .msg_iovlen = 1,
|
||||
struct msghdr msg = { .msg_iov = iov, .msg_iovlen = 2,
|
||||
.msg_control = buf.bytes,
|
||||
.msg_controllen = sizeof (buf) };
|
||||
struct cmsghdr *cmsg = CMSG_FIRSTHDR (&msg);
|
||||
|
@ -238,16 +238,19 @@ get_mapping (request_type type, const char *key,
|
||||
|
||||
/* Room for the data sent along with the file descriptor. We expect
|
||||
the key name back. */
|
||||
struct iovec iov[1];
|
||||
uint64_t mapsize;
|
||||
struct iovec iov[2];
|
||||
iov[0].iov_base = resdata;
|
||||
iov[0].iov_len = keylen;
|
||||
iov[1].iov_base = &mapsize;
|
||||
iov[1].iov_len = sizeof (mapsize);
|
||||
|
||||
union
|
||||
{
|
||||
struct cmsghdr hdr;
|
||||
char bytes[CMSG_SPACE (sizeof (int))];
|
||||
} buf;
|
||||
struct msghdr msg = { .msg_iov = iov, .msg_iovlen = 1,
|
||||
struct msghdr msg = { .msg_iov = iov, .msg_iovlen = 2,
|
||||
.msg_control = buf.bytes,
|
||||
.msg_controllen = sizeof (buf) };
|
||||
struct cmsghdr *cmsg = CMSG_FIRSTHDR (&msg);
|
||||
@ -268,10 +271,7 @@ get_mapping (request_type type, const char *key,
|
||||
# ifndef MSG_CMSG_CLOEXEC
|
||||
# define MSG_CMSG_CLOEXEC 0
|
||||
# endif
|
||||
if (__builtin_expect (TEMP_FAILURE_RETRY (__recvmsg (sock, &msg,
|
||||
MSG_CMSG_CLOEXEC))
|
||||
!= keylen, 0))
|
||||
goto out_close2;
|
||||
ssize_t n = TEMP_FAILURE_RETRY (__recvmsg (sock, &msg, MSG_CMSG_CLOEXEC));
|
||||
|
||||
if (__builtin_expect (CMSG_FIRSTHDR (&msg) == NULL
|
||||
|| (CMSG_FIRSTHDR (&msg)->cmsg_len
|
||||
@ -280,14 +280,25 @@ get_mapping (request_type type, const char *key,
|
||||
|
||||
mapfd = *(int *) CMSG_DATA (cmsg);
|
||||
|
||||
struct stat64 st;
|
||||
if (__builtin_expect (strcmp (resdata, key) != 0, 0)
|
||||
|| __builtin_expect (fstat64 (mapfd, &st) != 0, 0)
|
||||
|| __builtin_expect (st.st_size < sizeof (struct database_pers_head), 0))
|
||||
if (__builtin_expect (n != keylen && n != keylen + sizeof (mapsize), 0))
|
||||
goto out_close;
|
||||
|
||||
if (__builtin_expect (strcmp (resdata, key) != 0, 0))
|
||||
goto out_close;
|
||||
|
||||
if (__builtin_expect (n == keylen, 0))
|
||||
{
|
||||
struct stat64 st;
|
||||
if (__builtin_expect (fstat64 (mapfd, &st) != 0, 0)
|
||||
|| __builtin_expect (st.st_size < sizeof (struct database_pers_head),
|
||||
0))
|
||||
goto out_close;
|
||||
|
||||
mapsize = st.st_size;
|
||||
}
|
||||
|
||||
/* The file is large enough, map it now. */
|
||||
void *mapping = __mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, mapfd, 0);
|
||||
void *mapping = __mmap (NULL, mapsize, PROT_READ, MAP_SHARED, mapfd, 0);
|
||||
if (__builtin_expect (mapping != MAP_FAILED, 1))
|
||||
{
|
||||
/* Check whether the database is correct and up-to-date. */
|
||||
@ -302,7 +313,7 @@ get_mapping (request_type type, const char *key,
|
||||
< time (NULL)), 0))
|
||||
{
|
||||
out_unmap:
|
||||
__munmap (mapping, st.st_size);
|
||||
__munmap (mapping, mapsize);
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
@ -310,7 +321,7 @@ get_mapping (request_type type, const char *key,
|
||||
ALIGN)
|
||||
+ head->data_size);
|
||||
|
||||
if (__builtin_expect (st.st_size < size, 0))
|
||||
if (__builtin_expect (mapsize < size, 0))
|
||||
goto out_unmap;
|
||||
|
||||
/* Allocate a record for the mapping. */
|
||||
|
Loading…
Reference in New Issue
Block a user