From 01cdc07f9566000388f79999465910d4e81c00e1 Mon Sep 17 00:00:00 2001 From: benrubson Date: Wed, 20 Apr 2016 16:34:01 +0200 Subject: [PATCH] fixes a never ending unmounting case, and log if we still have opened files --- encfs/main.cpp | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/encfs/main.cpp b/encfs/main.cpp index ab69992..4bc6570 100644 --- a/encfs/main.cpp +++ b/encfs/main.cpp @@ -523,19 +523,6 @@ void *encfs_init(fuse_conn_info *conn) { } void encfs_destroy(void *_ctx) { - EncFS_Context *ctx = (EncFS_Context *)_ctx; - if (ctx->args->idleTimeout > 0) { - ctx->running = false; - - // wake up the thread if it is waiting.. - VLOG(1) << "waking up monitoring thread"; - pthread_mutex_lock(&ctx->wakeupMutex); - pthread_cond_signal(&ctx->wakeupCond); - pthread_mutex_unlock(&ctx->wakeupMutex); - VLOG(1) << "joining with idle monitoring thread"; - pthread_join(ctx->monitorThread, 0); - VLOG(1) << "join done"; - } } int main(int argc, char *argv[]) { @@ -691,6 +678,18 @@ int main(int argc, char *argv[]) { } catch (...) { RLOG(ERROR) << "Internal error: Caught unexpected exception"; } + + if (ctx->args->idleTimeout > 0) { + ctx->running = false; + // wake up the thread if it is waiting.. + VLOG(1) << "waking up monitoring thread"; + pthread_mutex_lock(&ctx->wakeupMutex); + pthread_cond_signal(&ctx->wakeupCond); + pthread_mutex_unlock(&ctx->wakeupMutex); + VLOG(1) << "joining with idle monitoring thread"; + pthread_join(ctx->monitorThread, 0); + VLOG(1) << "join done"; + } } // cleanup so that we can check for leaked resources.. @@ -718,7 +717,7 @@ static void *idleMonitor(void *_arg) { std::shared_ptr arg = ctx->args; const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval; - int idleCycles = 0; + int idleCycles = -1; pthread_mutex_lock(&ctx->wakeupMutex); @@ -732,13 +731,20 @@ static void *idleMonitor(void *_arg) { if (idleCycles >= timeoutCycles) { int openCount = ctx->openFileCount(); - if (openCount == 0 && unmountFS(ctx)) { - // wait for main thread to wake us up - pthread_cond_wait(&ctx->wakeupCond, &ctx->wakeupMutex); - break; + if (openCount == 0) { + if (unmountFS(ctx)) { + // wait for main thread to wake us up + pthread_cond_wait(&ctx->wakeupCond, &ctx->wakeupMutex); + break; + } + } + else { + RLOG(WARNING) << "Filesystem " + << arg->opts->mountPoint + << " inactivity detected, but still " + << openCount + << " opened files"; } - - VLOG(1) << "num open files: " << openCount; } VLOG(1) << "idle cycle count: " << idleCycles << ", timeout after "