aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/early.go
blob: 218105f26acba310101e0898e225ecb9f74bb5b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package internal

import (
	"errors"
	"fmt"
	"io/fs"
	"os"
)

const (
	systemdCheckPath = "/run/systemd/system"
)

var SdBootedV = func() bool {
	if v, err := SdBooted(); err != nil {
		fmt.Println("warn: read systemd marker:", err)
		return false
	} else {
		return v
	}
}()

// SdBooted implements https://www.freedesktop.org/software/systemd/man/sd_booted.html
func SdBooted() (bool, error) {
	_, err := os.Stat(systemdCheckPath)
	if err != nil {
		if errors.Is(err, fs.ErrNotExist) {
			err = nil
		}
		return false, err
	}

	return true, nil
}