scope: count successful cgroup additions when delegating via D-Bus
authorJonas Witschel <diabonas@archlinux.org>
Wed, 10 Nov 2021 21:46:35 +0000 (22:46 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 13 Jan 2022 09:51:56 +0000 (10:51 +0100)
commit69b59e4f601a203b030e0f0862f12d9586bd8e9d
tree631e468fda5c781aa01b30b8d73e6b6a205fb27e
parentca9cb08051747800c981d62cb745cabac4a919d7
scope: count successful cgroup additions when delegating via D-Bus

Since commit 8d3e4ac7cd37200d1431411a4b98925a24b7d9b3 ("scope: refuse
activation of scopes if no PIDs to add are left") all "systemd-run --scope
--user" calls fail because cgroup attachments delegated to the system instance
are not counted towards successful additions. Fix this by incrementing the
return value in case unit_attach_pid_to_cgroup_via_bus() succeeds, similar to
what happens when cg_attach() succeeds directly.

Note that this can *not* distinguish the case when
unit_attach_pid_to_cgroup_via_bus() has been run successfully, but all
processes to attach are gone in the meantime, unlike the checks that commit
8d3e4ac7cd37200d1431411a4b98925a24b7d9b3 adds for the system instance. This is
because even though unit_attach_pid_to_cgroup_via_bus() leads to an internal
unit_attach_pids_to_cgroup() call, the return value over D-Bus does not include
the number of successfully attached processes and is always NULL on success.

Fixes: #21297

(cherry picked from commit c65417a01121301fdf7f8514ee7663d287af3a72)
(cherry picked from commit be509064edba9863521a77a4a20a6e1a0971693e)
src/core/cgroup.c