From 0a4db7d9e9801a416602b52281537991ba1463c0 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 8 Sep 2019 16:29:20 +0200 Subject: Fix -idle unmounting despite activity Fixes https://github.com/rfjakob/gocryptfs/issues/421 --- mount.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'mount.go') diff --git a/mount.go b/mount.go index eeeffe8..446708e 100644 --- a/mount.go +++ b/mount.go @@ -181,18 +181,18 @@ func idleMonitor(idleTimeout time.Duration, fs *fusefrontend.FS, srv *fuse.Serve timeoutCycles := int(math.Ceil(float64(idleTimeout) / float64(sleepTimeBetweenChecks))) idleCount := 0 for { - // Atomically check whether the access flag is set and reset it to 0 if so. - recentAccess := atomic.CompareAndSwapUint32(&fs.AccessedSinceLastCheck, 1, 0) + // Atomically check whether the flag is 0 and reset it to 1 if so. + isIdle := !atomic.CompareAndSwapUint32(&fs.IsIdle, 0, 1) // Any form of current or recent access resets the idle counter. openFileCount := openfiletable.CountOpenFiles() - if recentAccess || openFileCount > 0 { + if !isIdle || openFileCount > 0 { idleCount = 0 } else { idleCount++ } tlog.Debug.Printf( - "Checking for idle (recentAccess = %t, open = %d): %s", - recentAccess, openFileCount, time.Now().String()) + "Checking for idle (isIdle = %t, open = %d): %s", + isIdle, openFileCount, time.Now().String()) if idleCount > 0 && idleCount%timeoutCycles == 0 { tlog.Info.Printf("Filesystem idle; unmounting: %s", mountpoint) unmount(srv, mountpoint) -- cgit v1.2.3