Skip to content

Commit

Permalink
Merge pull request #2116 from filbranden/running1
Browse files Browse the repository at this point in the history
Avoid the dependency on cgo through go-systemd/util package
  • Loading branch information
Mrunal Patel authored Aug 25, 2019
2 parents 2e94378 + 4ca0077 commit f7b6588
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 640 deletions.
20 changes: 17 additions & 3 deletions libcontainer/cgroups/systemd/apply_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"time"

systemdDbus "github.com/coreos/go-systemd/dbus"
systemdUtil "github.com/coreos/go-systemd/util"
"github.com/godbus/dbus"
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
Expand Down Expand Up @@ -86,8 +85,23 @@ func newProp(name string, units interface{}) systemdDbus.Property {
}
}

// NOTE: This function comes from package github.com/coreos/go-systemd/util
// It was borrowed here to avoid a dependency on cgo.
//
// 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
func isRunningSystemd() bool {
fi, err := os.Lstat("/run/systemd/system")
if err != nil {
return false
}
return fi.IsDir()
}

func UseSystemd() bool {
if !systemdUtil.IsRunningSystemd() {
if !isRunningSystemd() {
return false
}

Expand Down Expand Up @@ -164,7 +178,7 @@ func UseSystemd() bool {
}

func NewSystemdCgroupsManager() (func(config *configs.Cgroup, paths map[string]string) cgroups.Manager, error) {
if !systemdUtil.IsRunningSystemd() {
if !isRunningSystemd() {
return nil, fmt.Errorf("systemd not running on this host, can't use systemd as a cgroups.Manager")
}
return func(config *configs.Cgroup, paths map[string]string) cgroups.Manager {
Expand Down
1 change: 0 additions & 1 deletion vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16
github.com/vishvananda/netlink 1e2e08e8a2dcdacaae3f14ac44c5cfa31361f270
# systemd integration.
github.com/coreos/go-systemd v14
github.com/coreos/pkg v3
github.com/godbus/dbus v3
github.com/golang/protobuf 18c9bb3261723cd5401db4d0c9fbc5c3b6c70fe8
# Command-line interface.
Expand Down
90 changes: 0 additions & 90 deletions vendor/github.com/coreos/go-systemd/util/util.go

This file was deleted.

174 changes: 0 additions & 174 deletions vendor/github.com/coreos/go-systemd/util/util_cgo.go

This file was deleted.

23 changes: 0 additions & 23 deletions vendor/github.com/coreos/go-systemd/util/util_stub.go

This file was deleted.

Loading

0 comments on commit f7b6588

Please sign in to comment.