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
This commit is contained in:
Nick Craig-Wood 2020-11-27 10:50:36 +00:00
parent 83406bc473
commit f7d9b15707

View File

@ -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)