[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r9039: Apparently, we actually hit the nasty mmap-then-unlink behav (in tor/trunk: . src/or)
- To: or-cvs@xxxxxxxxxxxxx
- Subject: [or-cvs] r9039: Apparently, we actually hit the nasty mmap-then-unlink behav (in tor/trunk: . src/or)
- From: nickm@xxxxxxxx
- Date: Thu, 7 Dec 2006 10:07:33 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Thu, 07 Dec 2006 10:07:41 -0500
- Reply-to: or-talk@xxxxxxxxxxxxx
- Sender: owner-or-cvs@xxxxxxxxxxxxx
Author: nickm
Date: 2006-12-07 10:07:33 -0500 (Thu, 07 Dec 2006)
New Revision: 9039
Modified:
tor/trunk/
tor/trunk/src/or/routerlist.c
Log:
r11454@Kushana: nickm | 2006-12-07 10:07:24 -0500
Apparently, we actually hit the nasty mmap-then-unlink behavior. Fix it.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r11454] on c95137ef-5f19-0410-b913-86e773d04f59
Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c 2006-12-07 15:06:38 UTC (rev 9038)
+++ tor/trunk/src/or/routerlist.c 2006-12-07 15:07:33 UTC (rev 9039)
@@ -237,7 +237,7 @@
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 @@
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,18 +288,23 @@
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) {
smartlist_t *lst = (i == 0) ? old_routers : routers;