chiark / gitweb /
core: add new new bus call for migrating foreign processes to scope/service units
authorLennart Poettering <lennart@poettering.net>
Wed, 7 Feb 2018 21:52:52 +0000 (22:52 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:58:54 +0000 (07:58 +0200)
commit9d295ad80401603584c56bac3943636bdb17925a
tree41281c4a8127d9bbeed2343cd034734cd642dd6e
parentaa593c9d880456820a90d731e63abaa75083b93d
core: add new new bus call for migrating foreign processes to scope/service units

This adds a new bus call to service and scope units called
AttachProcesses() that moves arbitrary processes into the cgroup of the
unit. The primary user for this new API is systemd itself: the systemd
--user instance uses this call of the systemd --system instance to
migrate processes if itself gets the request to migrate processes and
the kernel refuses this due to access restrictions.

The primary use-case of this is to make "systemd-run --scope --user …"
invoked from user session scopes work correctly on pure cgroupsv2
environments. There, the kernel refuses to migrate processes between two
unprivileged-owned cgroups unless the requestor as well as the ownership
of the closest parent cgroup all match. This however is not the case
between the session-XYZ.scope unit of a login session and the
user@ABC.service of the systemd --user instance.

The new logic always tries to move the processes on its own, but if
that doesn't work when being the user manager, then the system manager
is asked to do it instead.

The new operation is relatively restrictive: it will only allow to move
the processes like this if the caller is root, or the UID of the target
unit, caller and process all match. Note that this means that
unprivileged users cannot attach processes to scope units, as those do
not have "owning" users (i.e. they have now User= field).

Fixes: #3388
src/core/cgroup.c
src/core/cgroup.h