From 33c6125da676dd73fd7748f2e1af1cd8cd8bc35c Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 27 Mar 2020 14:59:46 -0700 Subject: [PATCH] systemd: Export IsSystemdRunning() function Signed-off-by: Mrunal Patel --- libcontainer/cgroups/systemd/apply_nosystemd.go | 2 +- libcontainer/cgroups/systemd/apply_systemd.go | 4 ++-- libcontainer/integration/exec_test.go | 8 ++++---- utils_linux.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libcontainer/cgroups/systemd/apply_nosystemd.go b/libcontainer/cgroups/systemd/apply_nosystemd.go index ef0db5ae..5318a1e9 100644 --- a/libcontainer/cgroups/systemd/apply_nosystemd.go +++ b/libcontainer/cgroups/systemd/apply_nosystemd.go @@ -14,7 +14,7 @@ type Manager struct { Paths map[string]string } -func UseSystemd() bool { +func IsRunningSystemd() bool { return false } diff --git a/libcontainer/cgroups/systemd/apply_systemd.go b/libcontainer/cgroups/systemd/apply_systemd.go index cd83fadd..1d845771 100644 --- a/libcontainer/cgroups/systemd/apply_systemd.go +++ b/libcontainer/cgroups/systemd/apply_systemd.go @@ -89,7 +89,7 @@ func newProp(name string, units interface{}) systemdDbus.Property { // 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 -func isRunningSystemd() bool { +func IsRunningSystemd() bool { fi, err := os.Lstat("/run/systemd/system") if err != nil { return false @@ -116,7 +116,7 @@ func UseSystemd() bool { } func NewSystemdCgroupsManager() (func(config *configs.Cgroup, paths map[string]string) cgroups.Manager, error) { - if !isRunningSystemd() { + if !IsRunningSystemd() { return nil, fmt.Errorf("systemd not running on this host, can't use systemd as a cgroups.Manager") } if cgroups.IsCgroup2UnifiedMode() { diff --git a/libcontainer/integration/exec_test.go b/libcontainer/integration/exec_test.go index fa28e2db..3808099a 100644 --- a/libcontainer/integration/exec_test.go +++ b/libcontainer/integration/exec_test.go @@ -506,7 +506,7 @@ func TestFreeze(t *testing.T) { } func TestSystemdFreeze(t *testing.T) { - if !systemd.UseSystemd() { + if !systemd.IsRunningSystemd() { t.Skip("Systemd is unsupported") } testFreeze(t, true) @@ -563,7 +563,7 @@ func TestCpuShares(t *testing.T) { } func TestCpuSharesSystemd(t *testing.T) { - if !systemd.UseSystemd() { + if !systemd.IsRunningSystemd() { t.Skip("Systemd is unsupported") } testCpuShares(t, true) @@ -598,7 +598,7 @@ func TestPids(t *testing.T) { } func TestPidsSystemd(t *testing.T) { - if !systemd.UseSystemd() { + if !systemd.IsRunningSystemd() { t.Skip("Systemd is unsupported") } testPids(t, true) @@ -684,7 +684,7 @@ func TestRunWithKernelMemory(t *testing.T) { } func TestRunWithKernelMemorySystemd(t *testing.T) { - if !systemd.UseSystemd() { + if !systemd.IsRunningSystemd() { t.Skip("Systemd is unsupported") } testRunWithKernelMemory(t, true) diff --git a/utils_linux.go b/utils_linux.go index 1dedc827..e4ba344c 100644 --- a/utils_linux.go +++ b/utils_linux.go @@ -47,7 +47,7 @@ func loadFactory(context *cli.Context) (libcontainer.Factory, error) { cgroupManager = libcontainer.RootlessCgroupfs } if context.GlobalBool("systemd-cgroup") { - if systemd.UseSystemd() { + if systemd.IsRunningSystemd() { cgroupManager = libcontainer.SystemdCgroups } else { return nil, fmt.Errorf("systemd cgroup flag passed, but systemd support for managing cgroups is not available")