aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--util.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/util.go b/util.go
new file mode 100644
index 00000000..4c8484b7
--- /dev/null
+++ b/util.go
@@ -0,0 +1,28 @@
+package main
+
+import (
+ "errors"
+ "fmt"
+ "io/fs"
+ "os"
+)
+
+const (
+ systemdCheckPath = "/run/systemd/system"
+)
+
+// https://www.freedesktop.org/software/systemd/man/sd_booted.html
+func sdBooted() bool {
+ _, err := os.Stat(systemdCheckPath)
+ if err != nil {
+ if verbose {
+ if errors.Is(err, fs.ErrNotExist) {
+ fmt.Println("System not booted through systemd")
+ } else {
+ fmt.Println("Error accessing", systemdCheckPath+":", err.Error())
+ }
+ }
+ return false
+ }
+ return true
+}