From e7ba5cacc6470c41c37601e8745628708ce4c8a8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 9 Nov 2020 15:15:45 +0100 Subject: [PATCH] daemon: un-export IsRunningSystemd() This utility was added after 19.03, and is only used in the daemon code itself, so we can un-export it, until there's an external use for it. Also updated the description, because the runc code already copied it from coreos/go-systemd, so better to describe the actual source. Signed-off-by: Sebastiaan van Stijn --- daemon/daemon_unix.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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