aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-12-07 15:07:33 +0000
committerNick Mathewson <nickm@torproject.org>2006-12-07 15:07:33 +0000
commite6c467fe07163d44dc3b62007f09b6b95a572c28 (patch)
tree836040578038d3220ce159341f1ca906a49099ef /src/or
parent97e5e78afd8acba67abc4a12d997ee81a8def0f7 (diff)
downloadtor-e6c467fe07163d44dc3b62007f09b6b95a572c28.tar.gz
tor-e6c467fe07163d44dc3b62007f09b6b95a572c28.zip
r11454@Kushana: nickm | 2006-12-07 10:07:24 -0500
Apparently, we actually hit the nasty mmap-then-unlink behavior. Fix it. svn:r9039
Diffstat (limited to 'src/or')
-rw-r--r--src/or/routerlist.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 0745bc5a28..b87c3fa2b9 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -237,7 +237,7 @@ router_rebuild_store(int force)
or_options_t *options;
size_t fname_len;
smartlist_t *chunk_list = NULL;
- char *fname = NULL;
+ char *fname = NULL, *fname_tmp = NULL;
int r = -1, i;
off_t offset = 0;
smartlist_t *old_routers, *routers;
@@ -255,7 +255,11 @@ router_rebuild_store(int force)
options = get_options();
fname_len = strlen(options->DataDirectory)+32;
fname = tor_malloc(fname_len);
+ fname_tmp = tor_malloc(fname_len);
tor_snprintf(fname, fname_len, "%s/cached-routers", options->DataDirectory);
+ tor_snprintf(fname_tmp, fname_len, "%s/cached-routers.tmp",
+ options->DataDirectory);
+
chunk_list = smartlist_create();
old_routers = smartlist_create();
@@ -284,17 +288,22 @@ router_rebuild_store(int force)
smartlist_add(chunk_list, c);
});
}
- if (write_chunks_to_file(fname, chunk_list, 1)<0) {
+ if (write_chunks_to_file(fname_tmp, chunk_list, 1)<0) {
log_warn(LD_FS, "Error writing router store to disk.");
goto done;
}
/* Our mmap is now invalid. */
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);
}
+ if (replace_file(fname_tmp, fname)<0) {
+ log_warn(LD_FS, "Error replacing old router store.");
+ goto done;
+ }
+
+ routerlist->mmap_descriptors = tor_mmap_file(fname);
+ if (! routerlist->mmap_descriptors)
+ log_warn(LD_FS, "Unable to mmap new descriptor file at '%s'.",fname);
offset = 0;
for (i = 0; i < 2; ++i) {