From b0aff891661dfa2f438a7264607a4e6e9caef026 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Thu, 12 Sep 2024 20:53:33 +0900 Subject: app: handle launch method in New function Signed-off-by: Ophestra Umiker --- internal/util/early.go | 12 ++++++++++++ internal/util/std.go | 16 ++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 internal/util/early.go (limited to 'internal/util') diff --git a/internal/util/early.go b/internal/util/early.go new file mode 100644 index 00000000..ba7375c7 --- /dev/null +++ b/internal/util/early.go @@ -0,0 +1,12 @@ +package util + +import "fmt" + +var SdBootedV = func() bool { + if v, err := SdBooted(); err != nil { + fmt.Println("warn: read systemd marker:", err) + return false + } else { + return v + } +}() diff --git a/internal/util/std.go b/internal/util/std.go index 5c37a0d7..4f304fb6 100644 --- a/internal/util/std.go +++ b/internal/util/std.go @@ -8,7 +8,6 @@ import ( "path" "git.ophivana.moe/cat/fortify/internal/state" - "git.ophivana.moe/cat/fortify/internal/system" ) const ( @@ -22,19 +21,16 @@ const ( ) // SdBooted implements https://www.freedesktop.org/software/systemd/man/sd_booted.html -func SdBooted() bool { +func SdBooted() (bool, error) { _, err := os.Stat(systemdCheckPath) if err != nil { - if system.V.Verbose { - if errors.Is(err, fs.ErrNotExist) { - fmt.Println("System not booted through systemd") - } else { - fmt.Println("Error accessing", systemdCheckPath+":", err.Error()) - } + if errors.Is(err, fs.ErrNotExist) { + err = nil } - return false + return false, err } - return true + + return true, nil } // DiscoverPulseCookie try various standard methods to discover the current user's PulseAudio authentication cookie -- cgit v1.3.1