diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-08-29 13:02:02 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-08-29 13:02:02 -0400 |
commit | 5e97b34daa27f6e0ca1c233e31d00ab8620284f0 (patch) | |
tree | 572fc27ba312e6b7e1215085b6ba19d359bdcf24 /src/or/conscache.c | |
parent | 6307a759ed5ce48f31a5c36b08f2563cbb226389 (diff) | |
download | tor-5e97b34daa27f6e0ca1c233e31d00ab8620284f0.tar.gz tor-5e97b34daa27f6e0ca1c233e31d00ab8620284f0.zip |
On windows, don't force-unlink active conscache objects.
Part of a fix for bug 22752: We can't unlink these because Windows
doesn't allow you to unlink an in-use file.
Diffstat (limited to 'src/or/conscache.c')
-rw-r--r-- | src/or/conscache.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/or/conscache.c b/src/or/conscache.c index 5ffa129bbe..c30d1998c6 100644 --- a/src/or/conscache.c +++ b/src/or/conscache.c @@ -9,6 +9,11 @@ #define CCE_MAGIC 0x17162253 +#ifdef _WIN32 +/* On Windows, unlink won't work if there's an active mmap. */ +#define MUST_UNMAP_TO_UNLINK +#endif + /** * A consensus_cache_entry_t is a reference-counted handle to an * item in a consensus_cache_t. It can be mmapped into RAM, or not, @@ -406,23 +411,36 @@ int consensus_cache_get_n_filenames_available(consensus_cache_t *cache) { tor_assert(cache); - int max = storage_dir_get_max_files(cache->dir); + int max = cache->max_entries; int used = smartlist_len(storage_dir_list(cache->dir)); +#ifdef MUST_UNMAP_TO_UNLINK + if (used > max) + return 0; +#else tor_assert_nonfatal(max >= used); +#endif return max - used; } /** * Delete every element of <b>cache</b> has been marked with - * consensus_cache_entry_mark_for_removal. If <b>force</b> is false, - * retain those entries which are not in use except by the cache. + * consensus_cache_entry_mark_for_removal. If <b>force</b> is false, + * retain those entries which are in use by something other than the cache. */ void consensus_cache_delete_pending(consensus_cache_t *cache, int force) { SMARTLIST_FOREACH_BEGIN(cache->entries, consensus_cache_entry_t *, ent) { tor_assert_nonfatal(ent->in_cache == cache); - if (! force) { + int force_ent = force; +#ifdef MUST_UNMAP_TO_UNLINK + /* We cannot delete anything with an active mmap on win32, so no + * force-deletion. */ + if (ent->map) { + force_ent = 0; + } +#endif + if (! force_ent) { if (ent->refcnt > 1 || BUG(ent->in_cache == NULL)) { /* Somebody is using this entry right now */ continue; |