diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 8754d4f972..930231a4ac 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -638,14 +638,20 @@ func UsingSystemd(config *config.Config) bool { return true } // On cgroup v2 hosts, default to systemd driver - if getCD(config) == "" && cgroups.Mode() == cgroups.Unified && IsRunningSystemd() { + if getCD(config) == "" && cgroups.Mode() == cgroups.Unified && isRunningSystemd() { return true } return false } -// IsRunningSystemd is from https://github.com/opencontainers/runc/blob/46be7b612e2533c494e6a251111de46d8e286ed5/libcontainer/cgroups/systemd/common.go#L27-L33 -func IsRunningSystemd() bool { +// 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. +// http://www.freedesktop.org/software/systemd/man/sd_booted.html +// +// 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