aboutsummaryrefslogtreecommitdiff
path: root/src/or/microdesc.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-06-13 09:40:32 -0400
committerNick Mathewson <nickm@torproject.org>2013-06-13 09:40:32 -0400
commit25dddf7a8f30699242b52fce115f29401f63ee9c (patch)
tree1b353ff92a3f30b3e8a94804f580b223555ac906 /src/or/microdesc.c
parent74a534be15a26cddb8b134757416a7550072f44b (diff)
parente602c4031b57f0780661ce0473a5e30d187d385c (diff)
downloadtor-25dddf7a8f30699242b52fce115f29401f63ee9c.tar
tor-25dddf7a8f30699242b52fce115f29401f63ee9c.tar.gz
Merge remote-tracking branch 'public/bug8822' into maint-0.2.4
Diffstat (limited to 'src/or/microdesc.c')
-rw-r--r--src/or/microdesc.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/or/microdesc.c b/src/or/microdesc.c
index d9955c7b4..05e3b4181 100644
--- a/src/or/microdesc.c
+++ b/src/or/microdesc.c
@@ -75,6 +75,10 @@ dump_microdescriptor(int fd, microdesc_t *md, size_t *annotation_len_out)
{
ssize_t r = 0;
size_t written;
+ if (md->body == NULL) {
+ *annotation_len_out = 0;
+ return 0;
+ }
/* XXXX drops unknown annotations. */
if (md->last_listed) {
char buf[ISO_TIME_LEN+1];
@@ -447,7 +451,7 @@ microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
HT_FOREACH(mdp, microdesc_map, &cache->map) {
microdesc_t *md = *mdp;
size_t annotation_len;
- if (md->no_save)
+ if (md->no_save || !md->body)
continue;
size = dump_microdescriptor(fd, md, &annotation_len);
@@ -474,15 +478,29 @@ microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
smartlist_add(wrote, md);
}
+ /* We must do this unmap _before_ we call finish_writing_to_file(), or
+ * windows will not actually replace the file. */
+ if (cache->cache_content)
+ tor_munmap_file(cache->cache_content);
+
if (finish_writing_to_file(open_file) < 0) {
log_warn(LD_DIR, "Error rebuilding microdescriptor cache: %s",
strerror(errno));
+ /* Okay. Let's prevent from making things worse elsewhere. */
+ cache->cache_content = NULL;
+ HT_FOREACH(mdp, microdesc_map, &cache->map) {
+ microdesc_t *md = *mdp;
+ if (md->saved_location == SAVED_IN_CACHE) {
+ md->off = 0;
+ md->saved_location = SAVED_NOWHERE;
+ md->body = NULL;
+ md->bodylen = 0;
+ md->no_save = 1;
+ }
+ }
return -1;
}
- if (cache->cache_content)
- tor_munmap_file(cache->cache_content);
-
cache->cache_content = tor_mmap_file(cache->cache_fname);
if (!cache->cache_content && smartlist_len(wrote)) {