aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/early.go
blob: 81ca49cdd954ca9de8a70eba971465428d35aea1 (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
35
package internal

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

	"git.ophivana.moe/security/fortify/internal/fmsg"
)

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

var SdBootedV = func() bool {
	if v, err := SdBooted(); err != nil {
		fmsg.Println("cannot 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
}