func pimonLock() error { if xdg.FindRuntime(lockSuffix) != "" { return fmt.Errorf("pimon lock file already exists: %s", xdg.UserRuntime(lockSuffix)) } f, err := xdg.OpenRuntime(lockSuffix, os.O_EXCL|os.O_CREATE|os.O_WRONLY) if err != nil { return fmt.Errorf("cannot create pimon lock file: %v", err) } fmt.Fprintln(f, os.Getpid()) f.Close() return nil }
func pimonUnlock() { _ = os.Remove(xdg.UserRuntime(lockSuffix)) }