1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

daemon: use sync.Once for systemd detection

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-11-09 15:21:27 +01:00
parent e7ba5cacc6
commit a506630e57
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -14,6 +14,7 @@ import (
"runtime/debug"
"strconv"
"strings"
"sync"
"time"
"github.com/containerd/cgroups"
@ -644,6 +645,11 @@ func UsingSystemd(config *config.Config) bool {
return false
}
var (
runningSystemd bool
detectSystemd sync.Once
)
// isRunningSystemd checks whether the host was booted with systemd as its init
// system. This functions similarly to systemd's `sd_booted(3)`: internally, it
// checks whether /run/systemd/system/ exists and is a directory.
@ -652,11 +658,14 @@ func UsingSystemd(config *config.Config) bool {
// NOTE: This function comes from package github.com/coreos/go-systemd/util
// It was borrowed here to avoid a dependency on cgo.
func isRunningSystemd() bool {
fi, err := os.Lstat("/run/systemd/system")
if err != nil {
return false
}
return fi.IsDir()
detectSystemd.Do(func() {
fi, err := os.Lstat("/run/systemd/system")
if err != nil {
return
}
runningSystemd = fi.IsDir()
})
return runningSystemd
}
// verifyPlatformContainerSettings performs platform-specific validation of the