diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2019-09-06 15:29:03 +0200 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2019-09-12 08:35:26 +0200 |
commit | b94a5e241095a55a6838970148d296e109b2afd1 (patch) | |
tree | b53111eea42e9cc9c7b7736823dc1f3df7298a35 /utils/utils_supported.go | |
parent | 79ebb5f254d6f3498500f823cf1b856fed2e6149 (diff) | |
download | podman-b94a5e241095a55a6838970148d296e109b2afd1.tar.gz podman-b94a5e241095a55a6838970148d296e109b2afd1.tar.bz2 podman-b94a5e241095a55a6838970148d296e109b2afd1.zip |
utils: use the user session for systemd
when running as rootless, use the user session bus. It is already
implemented in the pkg/cgroups so just re-use it.
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'utils/utils_supported.go')
-rw-r--r-- | utils/utils_supported.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/utils/utils_supported.go b/utils/utils_supported.go index 8b0ba4438..8bc232179 100644 --- a/utils/utils_supported.go +++ b/utils/utils_supported.go @@ -3,6 +3,8 @@ package utils import ( + "github.com/containers/libpod/pkg/cgroups" + "github.com/containers/libpod/pkg/rootless" systemdDbus "github.com/coreos/go-systemd/dbus" "github.com/godbus/dbus" ) @@ -10,9 +12,19 @@ import ( // RunUnderSystemdScope adds the specified pid to a systemd scope func RunUnderSystemdScope(pid int, slice string, unitName string) error { var properties []systemdDbus.Property - conn, err := systemdDbus.New() - if err != nil { - return err + var conn *systemdDbus.Conn + var err error + + if rootless.IsRootless() { + conn, err = cgroups.GetUserConnection(rootless.GetRootlessUID()) + if err != nil { + return err + } + } else { + conn, err = systemdDbus.New() + if err != nil { + return err + } } properties = append(properties, systemdDbus.PropSlice(slice)) properties = append(properties, newProp("PIDs", []uint32{uint32(pid)})) |