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:
parent
e7ba5cacc6
commit
a506630e57
1 changed files with 14 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue