Automatically lazy-unmount when we get SIGINT or SIGTERM
This hides the dangling "Transport endpoint is not connected" mountpoint for everyone but processes that have file open inside the mountpoint.
This commit is contained in:
parent
e31d319c39
commit
af923d2d16
30
main.go
30
main.go
@ -4,9 +4,12 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/cryptfs"
|
||||
@ -188,10 +191,16 @@ func main() {
|
||||
}
|
||||
|
||||
fmt.Println("Filesystem ready.")
|
||||
if !foreground {
|
||||
// Send notification to our parent
|
||||
sendUsr1()
|
||||
// Jump into server loop
|
||||
}
|
||||
// Wait for SIGING in the background and unmount ourselves if we get it
|
||||
// This prevents a dangling "Transport endpoint is not connected" mountpoint
|
||||
handleSigint(srv, mountpoint)
|
||||
// Jump into server loop. Returns when it gets an umount request from the kernel.
|
||||
srv.Serve()
|
||||
// main returns with code 0
|
||||
}
|
||||
|
||||
func pathfsFrontend(key []byte, cipherdir string, mountpoint string, debug bool, openssl bool) *fuse.Server {
|
||||
@ -224,3 +233,22 @@ func pathfsFrontend(key []byte, cipherdir string, mountpoint string, debug bool,
|
||||
|
||||
return srv
|
||||
}
|
||||
|
||||
func handleSigint(srv *fuse.Server, mountpoint string) {
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, os.Interrupt)
|
||||
signal.Notify(ch, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-ch
|
||||
err := srv.Unmount()
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Printf("Trying lazy unmount\n")
|
||||
cmd := exec.Command("fusermount", "-u", "-z", mountpoint)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Run()
|
||||
}
|
||||
os.Exit(1)
|
||||
}()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user