summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/compat.c18
-rw-r--r--src/common/compat.h3
-rw-r--r--src/or/or.h4
-rw-r--r--src/or/routerlist.c22
4 files changed, 18 insertions, 29 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 1be039438e..f55baf9041 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -110,7 +110,7 @@ const char compat_c_id[] =
#ifdef HAVE_SYS_MMAN_H
tor_mmap_t *
-tor_mmap_file(const char *filename, const char **data, size_t *size_out)
+tor_mmap_file(const char *filename)
{
int fd; /* router file */
char *string;
@@ -119,7 +119,6 @@ tor_mmap_file(const char *filename, const char **data, size_t *size_out)
size_t size;
tor_assert(filename);
- tor_assert(size_out);
fd = open(filename, O_RDONLY, 0);
if (fd<0) {
@@ -143,8 +142,8 @@ tor_mmap_file(const char *filename, const char **data, size_t *size_out)
close(fd);
res = tor_malloc_zero(sizeof(tor_mmap_t));
- *data = res->data = string;
- *size_out = res->size = size;
+ res->data = string;
+ res->size = size;
return res;
}
@@ -160,7 +159,7 @@ typedef struct win_mmap_t {
HANDLE mmap_handle;
} tor_mmap_impl_t;
tor_mmap_t *
-tor_mmap_file(const char *filename, const char **data, size_t *size)
+tor_mmap_file(const char *filename)
{
win_mmap_t *res = tor_malloc_zero(sizeof(win_mmap_t));
res->mmap_handle = res->file_handle = INVALID_HANDLE_VALUE;
@@ -186,9 +185,6 @@ tor_mmap_file(const char *filename, const char **data, size_t *size)
if (!res->data)
goto err;
- *size = res->size;
- *data = res->data;
-
return &(res->base);
err:
tor_munmap_file(res);
@@ -209,15 +205,15 @@ tor_munmap_file(tor_mmap_t *handle)
}
#else
tor_mmap_t *
-tor_mmap_file(const char *filename, const char **data, size_t *size)
+tor_mmap_file(const char *filename)
{
char *res = read_file_to_str(filename, 1);
tor_mmap_t *handle;
if (! res)
return NULL;
handle = tor_malloc_zero(sizeof(tor_mmap_t));
- *data = handle->data = res;
- *size = handle->size = strlen(res) + 1;
+ handle->data = res;
+ handle->size = strlen(res) + 1;
return handle;
}
void
diff --git a/src/common/compat.h b/src/common/compat.h
index b842218f75..1b96c1a5c2 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -120,8 +120,7 @@ typedef struct tor_mmap_t {
size_t size;
} tor_mmap_t;
-tor_mmap_t *tor_mmap_file(const char *filename,
- const char **data, size_t *size);
+tor_mmap_t *tor_mmap_file(const char *filename);
void tor_munmap_file(tor_mmap_t *handle);
int tor_snprintf(char *str, size_t size, const char *format, ...)
diff --git a/src/or/or.h b/src/or/or.h
index dfdd8fe2e2..fe4651dfeb 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1018,9 +1018,7 @@ typedef struct {
* caching. */
smartlist_t *old_routers;
/** DOCDOC */
- const char *mmap_descriptors;
- size_t mmap_descriptors_len;
- tor_mmap_t *mmap_handle;
+ tor_mmap_t *mmap_descriptors;
} routerlist_t;
/** Information on router used when extending a circuit. (We don't need a
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index e9819ddd83..1984ddf28c 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -276,12 +276,10 @@ router_rebuild_store(int force)
goto done;
}
/* Our mmap is now invalid. */
- if (routerlist->mmap_handle) {
- tor_munmap_file(routerlist->mmap_handle);
- routerlist->mmap_handle = tor_mmap_file(fname,
- &routerlist->mmap_descriptors,
- &routerlist->mmap_descriptors_len);
- if (! routerlist->mmap_handle)
+ if (routerlist->mmap_descriptors) {
+ tor_munmap_file(routerlist->mmap_descriptors);
+ routerlist->mmap_descriptors = tor_mmap_file(fname);
+ if (! routerlist->mmap_descriptors)
log_warn(LD_FS, "Unable to mmap new descriptor file at '%s'.",fname);
}
@@ -340,12 +338,10 @@ router_reload_router_list(void)
router_journal_len = router_store_len = 0;
tor_snprintf(fname, fname_len, "%s/cached-routers", options->DataDirectory);
- routerlist->mmap_handle = tor_mmap_file(fname,
- &routerlist->mmap_descriptors,
- &routerlist->mmap_descriptors_len);
+ routerlist->mmap_descriptors = tor_mmap_file(fname);
if (routerlist->mmap_descriptors) {
- router_store_len = routerlist->mmap_descriptors_len;
- router_load_routers_from_string(routerlist->mmap_descriptors,
+ router_store_len = routerlist->mmap_descriptors->size;
+ router_load_routers_from_string(routerlist->mmap_descriptors->data,
SAVED_IN_CACHE, NULL);
}
@@ -1159,8 +1155,8 @@ signed_descriptor_get_body(signed_descriptor_t *desc)
tor_assert(len > 32);
if (desc->saved_location == SAVED_IN_CACHE && routerlist &&
routerlist->mmap_descriptors) {
- tor_assert(desc->saved_offset + len <= routerlist->mmap_descriptors_len);
- r = routerlist->mmap_descriptors + desc->saved_offset;
+ tor_assert(desc->saved_offset + len <= routerlist->mmap_descriptors->size);
+ r = routerlist->mmap_descriptors->data + desc->saved_offset;
} else {
r = desc->signed_descriptor_body;
}