From f7d9b157079bbf6c7145f94784a60f846f19c637 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 27 Nov 2020 10:50:36 +0000 Subject: [PATCH] cmount: don't call host.Umount if a signal has been received Before this change cgofuse and libatexit would race to see who could unmount the file system with unpredicatable results. On Linux it could report an error or not, depending. This change checks to see if umount is beng called from a signal and if so leaves the unmounting to cgofuse/libfuse. See #4804 --- cmd/cmount/mount.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/cmount/mount.go b/cmd/cmount/mount.go index 38503d8ae..07a45daab 100644 --- a/cmd/cmount/mount.go +++ b/cmd/cmount/mount.go @@ -19,6 +19,7 @@ import ( "github.com/pkg/errors" "github.com/rclone/rclone/cmd/mountlib" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/lib/atexit" "github.com/rclone/rclone/vfs" ) @@ -187,9 +188,17 @@ func mount(VFS *vfs.VFS, mountpoint string, opt *mountlib.Options) (<-chan error unmount := func() error { // Shutdown the VFS fsys.VFS.Shutdown() - fs.Debugf(nil, "Calling host.Unmount") - if host.Unmount() { - fs.Debugf(nil, "host.Unmount succeeded") + var umountOK bool + if atexit.Signalled() { + // If we have received a signal then FUSE will be shutting down already + fs.Debugf(nil, "Not calling host.Unmount as signal received") + umountOK = true + } else { + fs.Debugf(nil, "Calling host.Unmount") + umountOK = host.Unmount() + } + if umountOK { + fs.Debugf(nil, "Unmounted successfully") if runtime.GOOS == "windows" { if !waitFor(func() bool { _, err := os.Stat(mountpoint)