Simplify condition

This commit is contained in:
benrubson 2017-11-02 10:15:54 +01:00
parent 64806bf3ac
commit e0b2ad8f66

View File

@ -766,7 +766,7 @@ static void *idleMonitor(void *_arg) {
pthread_mutex_lock(&ctx->wakeupMutex); pthread_mutex_lock(&ctx->wakeupMutex);
while (ctx->running) { while (ctx->running) {
int usage, openCount, fdlock; int usage, openCount;
ctx->getAndResetUsageCounter(&usage, &openCount); ctx->getAndResetUsageCounter(&usage, &openCount);
if (usage == 0 && ctx->isMounted()) { if (usage == 0 && ctx->isMounted()) {
@ -783,9 +783,14 @@ static void *idleMonitor(void *_arg) {
if (openCount != 0) { if (openCount != 0) {
RLOG(WARNING) << "Filesystem inactive, but " << openCount RLOG(WARNING) << "Filesystem inactive, but " << openCount
<< " files opened: " << arg->opts->mountPoint; << " files opened: " << arg->opts->mountPoint;
} else if ((fdlock = open(arg->opts->mountPoint.c_str(),O_RDONLY)) == -1 || flock(fdlock, LOCK_EX|LOCK_NB) == -1) { } else {
/* try to lock the mount point to give an oportunity to handle races
with an automated tool or script using --idle. */
int fdlock = open(arg->opts->mountPoint.c_str(),O_RDONLY);
if (flock(fdlock, LOCK_EX|LOCK_NB) == -1) {
RLOG(WARNING) << "Filesystem inactive, but " RLOG(WARNING) << "Filesystem inactive, but "
<< "lock before unmount failed: " << arg->opts->mountPoint; << "lock before unmount failed: " << arg->opts->mountPoint;
close(fdlock);
} else { } else {
unmountres = unmountFS(ctx); unmountres = unmountFS(ctx);
flock(fdlock, LOCK_UN); flock(fdlock, LOCK_UN);
@ -797,6 +802,7 @@ static void *idleMonitor(void *_arg) {
} }
} }
} }
}
VLOG(1) << "idle cycle count: " << idleCycles << ", timeout after " VLOG(1) << "idle cycle count: " << idleCycles << ", timeout after "
<< timeoutCycles; << timeoutCycles;