aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-03-31 11:57:56 -0400
committerNick Mathewson <nickm@torproject.org>2014-03-31 11:57:56 -0400
commitc0441cca8b483882f5676b98081f0fe4b52d3ae1 (patch)
tree0f6234deb72feb4de4c80ecbf4b0f0b0e89269f7 /src/or
parent4ebad0d947cbb74b674468e6601894468629f814 (diff)
parent3118af2d5fca7999a94d73690d83463ddacf9acb (diff)
downloadtor-c0441cca8b483882f5676b98081f0fe4b52d3ae1.tar
tor-c0441cca8b483882f5676b98081f0fe4b52d3ae1.tar.gz
Merge branch 'bug8787_squashed'
Diffstat (limited to 'src/or')
-rw-r--r--src/or/config.c5
-rw-r--r--src/or/hibernate.c10
-rw-r--r--src/or/main.c17
-rw-r--r--src/or/microdesc.c21
-rw-r--r--src/or/networkstatus.c21
-rw-r--r--src/or/routerlist.c34
-rw-r--r--src/or/statefile.c10
7 files changed, 94 insertions, 24 deletions
diff --git a/src/or/config.c b/src/or/config.c
index da6aec0c1..909ac145a 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -6458,7 +6458,10 @@ remove_file_if_very_old(const char *fname, time_t now)
format_local_iso_time(buf, st.st_mtime);
log_notice(LD_GENERAL, "Obsolete file %s hasn't been modified since %s. "
"Removing it.", fname, buf);
- unlink(fname);
+ if (unlink(fname) != 0) {
+ log_warn(LD_FS, "Failed to unlink %s: %s",
+ fname, strerror(errno));
+ }
}
}
diff --git a/src/or/hibernate.c b/src/or/hibernate.c
index 607dec8cd..bbda8424f 100644
--- a/src/or/hibernate.c
+++ b/src/or/hibernate.c
@@ -648,7 +648,15 @@ read_bandwidth_usage(void)
{
char *fname = get_datadir_fname("bw_accounting");
- unlink(fname);
+ int res;
+
+ res = unlink(fname);
+ if (res != 0) {
+ log_warn(LD_FS,
+ "Failed to unlink %s: %s",
+ fname, strerror(errno));
+ }
+
tor_free(fname);
}
diff --git a/src/or/main.c b/src/or/main.c
index d1e48ba07..feca35c44 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -2574,10 +2574,19 @@ tor_cleanup(void)
time_t now = time(NULL);
/* Remove our pid file. We don't care if there was an error when we
* unlink, nothing we could do about it anyways. */
- if (options->PidFile)
- unlink(options->PidFile);
- if (options->ControlPortWriteToFile)
- unlink(options->ControlPortWriteToFile);
+ if (options->PidFile) {
+ if (unlink(options->PidFile) != 0) {
+ log_warn(LD_FS, "Couldn't unlink pid file %s: %s",
+ options->PidFile, strerror(errno));
+ }
+ }
+ if (options->ControlPortWriteToFile) {
+ if (unlink(options->ControlPortWriteToFile) != 0) {
+ log_warn(LD_FS, "Couldn't unlink control port file %s: %s",
+ options->ControlPortWriteToFile,
+ strerror(errno));
+ }
+ }
if (accounting_is_enabled(options))
accounting_record_bandwidth_usage(now, get_or_state());
or_state_mark_dirty(get_or_state(), 0); /* force an immediate save. */
diff --git a/src/or/microdesc.c b/src/or/microdesc.c
index 49773329c..ec85de0d6 100644
--- a/src/or/microdesc.c
+++ b/src/or/microdesc.c
@@ -275,6 +275,7 @@ void
microdesc_cache_clear(microdesc_cache_t *cache)
{
microdesc_t **entry, **next;
+
for (entry = HT_START(microdesc_map, &cache->map); entry; entry = next) {
microdesc_t *md = *entry;
next = HT_NEXT_RMV(microdesc_map, &cache->map, entry);
@@ -283,7 +284,13 @@ microdesc_cache_clear(microdesc_cache_t *cache)
}
HT_CLEAR(microdesc_map, &cache->map);
if (cache->cache_content) {
- tor_munmap_file(cache->cache_content);
+ int res = tor_munmap_file(cache->cache_content);
+ if (res != 0) {
+ log_warn(LD_FS,
+ "tor_munmap_file() failed clearing microdesc cache; "
+ "we are probably about to leak memory.");
+ /* TODO something smarter? */
+ }
cache->cache_content = NULL;
}
cache->total_len_seen = 0;
@@ -479,7 +486,7 @@ int
microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
{
open_file_t *open_file;
- int fd = -1;
+ int fd = -1, res;
microdesc_t **mdp;
smartlist_t *wrote;
ssize_t size;
@@ -546,8 +553,14 @@ microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
/* 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 (cache->cache_content) {
+ res = tor_munmap_file(cache->cache_content);
+ if (res != 0) {
+ log_warn(LD_FS,
+ "Failed to unmap old microdescriptor cache while rebuilding");
+ }
+ cache->cache_content = NULL;
+ }
if (finish_writing_to_file(open_file) < 0) {
log_warn(LD_DIR, "Error rebuilding microdescriptor cache: %s",
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 49478a734..74c4ca45a 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -1254,7 +1254,11 @@ networkstatus_set_current_consensus(const char *consensus,
/* Even if we had enough signatures, we'd never use this as the
* latest consensus. */
if (was_waiting_for_certs && from_cache)
- unlink(unverified_fname);
+ if (unlink(unverified_fname) != 0) {
+ log_warn(LD_FS,
+ "Failed to unlink %s: %s",
+ unverified_fname, strerror(errno));
+ }
}
goto done;
} else {
@@ -1264,8 +1268,13 @@ networkstatus_set_current_consensus(const char *consensus,
"consensus");
result = -2;
}
- if (was_waiting_for_certs && (r < -1) && from_cache)
- unlink(unverified_fname);
+ if (was_waiting_for_certs && (r < -1) && from_cache) {
+ if (unlink(unverified_fname) != 0) {
+ log_warn(LD_FS,
+ "Failed to unlink %s: %s",
+ unverified_fname, strerror(errno));
+ }
+ }
goto done;
}
}
@@ -1313,7 +1322,11 @@ networkstatus_set_current_consensus(const char *consensus,
waiting->body = NULL;
waiting->set_at = 0;
waiting->dl_failed = 0;
- unlink(unverified_fname);
+ if (unlink(unverified_fname) != 0) {
+ log_warn(LD_FS,
+ "Failed to unlink %s: %s",
+ unverified_fname, strerror(errno));
+ }
}
/* Reset the failure count only if this consensus is actually valid. */
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index c8232606b..f1bd12c19 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1064,8 +1064,11 @@ router_rebuild_store(int flags, desc_store_t *store)
/* Our mmap is now invalid. */
if (store->mmap) {
- tor_munmap_file(store->mmap);
+ int res = tor_munmap_file(store->mmap);
store->mmap = NULL;
+ if (res != 0) {
+ log_warn(LD_FS, "Unable to munmap route store in %s", fname);
+ }
}
if (replace_file(fname_tmp, fname)<0) {
@@ -1139,9 +1142,16 @@ router_reload_router_list_impl(desc_store_t *store)
fname = get_datadir_fname(store->fname_base);
- if (store->mmap) /* get rid of it first */
- tor_munmap_file(store->mmap);
- store->mmap = NULL;
+ if (store->mmap) {
+ /* get rid of it first */
+ int res = tor_munmap_file(store->mmap);
+ store->mmap = NULL;
+ if (res != 0) {
+ log_warn(LD_FS, "Failed to munmap %s", fname);
+ tor_free(fname);
+ return -1;
+ }
+ }
store->mmap = tor_mmap_file(fname);
if (store->mmap) {
@@ -2794,10 +2804,18 @@ routerlist_free(routerlist_t *rl)
signed_descriptor_free(sd));
smartlist_free(rl->routers);
smartlist_free(rl->old_routers);
- if (routerlist->desc_store.mmap)
- tor_munmap_file(routerlist->desc_store.mmap);
- if (routerlist->extrainfo_store.mmap)
- tor_munmap_file(routerlist->extrainfo_store.mmap);
+ if (rl->desc_store.mmap) {
+ int res = tor_munmap_file(routerlist->desc_store.mmap);
+ if (res != 0) {
+ log_warn(LD_FS, "Failed to munmap routerlist->desc_store.mmap");
+ }
+ }
+ if (rl->extrainfo_store.mmap) {
+ int res = tor_munmap_file(routerlist->extrainfo_store.mmap);
+ if (res != 0) {
+ log_warn(LD_FS, "Failed to munmap routerlist->extrainfo_store.mmap");
+ }
+ }
tor_free(rl);
router_dir_info_changed();
diff --git a/src/or/statefile.c b/src/or/statefile.c
index 8ab04763d..2251f25e9 100644
--- a/src/or/statefile.c
+++ b/src/or/statefile.c
@@ -260,7 +260,7 @@ or_state_set(or_state_t *new_state)
static void
or_state_save_broken(char *fname)
{
- int i;
+ int i, res;
file_status_t status;
char *fname2 = NULL;
for (i = 0; i < 100; ++i) {
@@ -274,7 +274,13 @@ or_state_save_broken(char *fname)
log_warn(LD_BUG, "Unable to parse state in \"%s\"; too many saved bad "
"state files to move aside. Discarding the old state file.",
fname);
- unlink(fname);
+ res = unlink(fname);
+ if (res != 0) {
+ log_warn(LD_FS,
+ "Also couldn't discard old state file \"%s\" because "
+ "unlink() failed: %s",
+ fname, strerror(errno));
+ }
} else {
log_warn(LD_BUG, "Unable to parse state in \"%s\". Moving it aside "
"to \"%s\". This could be a bug in Tor; please tell "