Skip to content

Commit

Permalink
systemd: Export IsSystemdRunning() function
Browse files Browse the repository at this point in the history
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
  • Loading branch information
mrunalp committed Mar 30, 2020
1 parent 4a9e174 commit 33c6125
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion libcontainer/cgroups/systemd/apply_nosystemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Manager struct {
Paths map[string]string
}

func UseSystemd() bool {
func IsRunningSystemd() bool {
return false
}

Expand Down
4 changes: 2 additions & 2 deletions libcontainer/cgroups/systemd/apply_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions libcontainer/integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 33c6125

Please sign in to comment.