mount,cmount: make sure we call unmount when exiting

This commit is contained in:
Nick Craig-Wood 2019-11-11 22:08:52 +00:00
parent 358f5a8084
commit c21a4fee58
2 changed files with 9 additions and 1 deletions
cmd
cmount
mount

View file

@ -21,6 +21,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rclone/rclone/cmd/mountlib" "github.com/rclone/rclone/cmd/mountlib"
"github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs"
"github.com/rclone/rclone/lib/atexit"
"github.com/rclone/rclone/vfs" "github.com/rclone/rclone/vfs"
"github.com/rclone/rclone/vfs/vfsflags" "github.com/rclone/rclone/vfs/vfsflags"
) )
@ -207,7 +208,7 @@ func mount(f fs.Fs, mountpoint string) (*vfs.VFS, <-chan error, func() error, er
// If noModTime is set then it // If noModTime is set then it
func Mount(f fs.Fs, mountpoint string) error { func Mount(f fs.Fs, mountpoint string) error {
// Mount it // Mount it
FS, errChan, _, err := mount(f, mountpoint) FS, errChan, unmount, err := mount(f, mountpoint)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to mount FUSE fs") return errors.Wrap(err, "failed to mount FUSE fs")
} }
@ -217,6 +218,10 @@ func Mount(f fs.Fs, mountpoint string) error {
sigHup := make(chan os.Signal, 1) sigHup := make(chan os.Signal, 1)
signal.Notify(sigHup, syscall.SIGHUP) signal.Notify(sigHup, syscall.SIGHUP)
atexit.Register(func() {
_ = unmount()
})
if err := sdnotify.Ready(); err != nil && err != sdnotify.ErrSdNotifyNoSocket { if err := sdnotify.Ready(); err != nil && err != sdnotify.ErrSdNotifyNoSocket {
return errors.Wrap(err, "failed to notify systemd") return errors.Wrap(err, "failed to notify systemd")
} }

View file

@ -137,6 +137,9 @@ func Mount(f fs.Fs, mountpoint string) error {
sigHup := make(chan os.Signal, 1) sigHup := make(chan os.Signal, 1)
signal.Notify(sigHup, syscall.SIGHUP) signal.Notify(sigHup, syscall.SIGHUP)
atexit.IgnoreSignals() atexit.IgnoreSignals()
atexit.Register(func() {
_ = unmount()
})
if err := sdnotify.Ready(); err != nil && err != sdnotify.ErrSdNotifyNoSocket { if err := sdnotify.Ready(); err != nil && err != sdnotify.ErrSdNotifyNoSocket {
return errors.Wrap(err, "failed to notify systemd") return errors.Wrap(err, "failed to notify systemd")