File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import (
1414 "runtime/debug"
1515 "strconv"
1616 "strings"
17+ "sync"
1718 "time"
1819
1920 "github.com/containerd/cgroups"
@@ -644,6 +645,11 @@ func UsingSystemd(config *config.Config) bool {
644645 return false
645646}
646647
648+ var (
649+ runningSystemd bool
650+ detectSystemd sync.Once
651+ )
652+
647653// isRunningSystemd checks whether the host was booted with systemd as its init
648654// system. This functions similarly to systemd's `sd_booted(3)`: internally, it
649655// checks whether /run/systemd/system/ exists and is a directory.
@@ -652,11 +658,14 @@ func UsingSystemd(config *config.Config) bool {
652658// NOTE: This function comes from package github.com/coreos/go-systemd/util
653659// It was borrowed here to avoid a dependency on cgo.
654660func isRunningSystemd () bool {
655- fi , err := os .Lstat ("/run/systemd/system" )
656- if err != nil {
657- return false
658- }
659- return fi .IsDir ()
661+ detectSystemd .Do (func () {
662+ fi , err := os .Lstat ("/run/systemd/system" )
663+ if err != nil {
664+ return
665+ }
666+ runningSystemd = fi .IsDir ()
667+ })
668+ return runningSystemd
660669}
661670
662671// verifyPlatformContainerSettings performs platform-specific validation of the
You can’t perform that action at this time.
0 commit comments