Ophestra Umiker
42e0b168e3
All checks were successful
test / test (push) Successful in 17s
The behaviour of print functions from package fmt is not thread safe. Functions provided by fmsg wrap around Logger methods. This makes prefix much cleaner and makes it easy to deal with future changes to logging. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
36 lines
596 B
Go
36 lines
596 B
Go
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
|
|
}
|