summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliaksey Kandratsenka <alk@tut.by>2011-05-06 18:20:14 -0700
committerDustin Sallings <dustin@spy.net>2011-05-07 12:31:57 -0700
commitc5c3c7d0489edc2ff098eed006c6ea358b33d320 (patch)
treea11553f3281be19534ec590a59c30ff615f684d0
parent5b4120ac4dc4bbbdb24f99596c56b0a3f3d60192 (diff)
downloadmemcached-c5c3c7d0489edc2ff098eed006c6ea358b33d320.tar.gz
workaround low mtime resolution by reloading isasl db few times
If isasl.pw is changed several times during one second (which is resolution of mtime in struct stat), then we'll have stale password database. To prevent that we keep reloading isasl password for 2 mtime check cycles. If mtime is still same, we can be sure that we haven't missed updates. Change-Id: Ia299aba6296b86ec0e569cf1d13bc9fbede0303a
-rw-r--r--daemon/isasl.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/daemon/isasl.c b/daemon/isasl.c
index 5ca1a39..bbc66d4 100644
--- a/daemon/isasl.c
+++ b/daemon/isasl.c
@@ -15,7 +15,10 @@
#include "isasl.h"
#include "memcached.h"
+#define MTIME_STABILITY_THRESHOLD 2
+
static struct stat prev_stat = { 0 };
+static int mtime_stability_counter;
static pthread_mutex_t uhash_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t sasl_db_thread_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -190,7 +193,7 @@ void sasl_dispose(sasl_conn_t **pconn)
static bool isasl_is_fresh(void)
{
- bool rv = false;
+ bool rv = true;
struct stat st;
const char *filename = get_isasl_filename();
@@ -198,7 +201,17 @@ static bool isasl_is_fresh(void)
if (stat(get_isasl_filename(), &st) < 0) {
perror(get_isasl_filename());
} else {
- rv = prev_stat.st_mtime == st.st_mtime;
+ rv = (prev_stat.st_mtime != st.st_mtime);
+ if (rv) {
+ /* if mtime changes, reset stability counter */
+ mtime_stability_counter = MTIME_STABILITY_THRESHOLD;
+ } else if (mtime_stability_counter) {
+ /* if mtime haven't changed, but counter hasn't
+ * reached zero, reply true (fresh data) and
+ * decrement counter */
+ mtime_stability_counter--;
+ rv = true;
+ }
prev_stat = st;
}
}
@@ -219,7 +232,7 @@ static void* check_isasl_db_thread(void* arg)
while (run) {
sleep(sleep_time);
- if (!isasl_is_fresh()) {
+ if (isasl_is_fresh()) {
load_user_db();
}