Resolve race condition issues

This commit is contained in:
Ben Sarmiento
2023-11-04 14:13:24 +01:00
parent b2e957cb4c
commit 4136310622
8 changed files with 136 additions and 26 deletions

38
internal/mount/mount.go Normal file
View File

@@ -0,0 +1,38 @@
package mount
import (
"errors"
"log"
"os"
"bazil.org/fuse"
"github.com/mdlayher/sdnotify"
)
func Mount(mountpoint string) error {
n, err := sdnotify.New()
if err != nil && !errors.Is(err, os.ErrNotExist) {
log.Fatalf("failed to open systemd notifier: %v", err)
}
err = n.Notify(
sdnotify.Statusf("service started successfully"),
sdnotify.Ready,
)
if err != nil {
log.Fatalf("failed to send ready notification: %v", err)
}
return Unmount(mountpoint, n)
}
func Unmount(mountpoint string, n *sdnotify.Notifier) error {
log.Println("Unmounting...")
err := n.Notify(
sdnotify.Statusf("service stopped successfully"),
sdnotify.Ready,
)
if err != nil {
log.Fatalf("failed to send stop notification: %v", err)
}
fuse.Unmount(mountpoint)
return nil
}