core: add GetUnitByPIDFD method and use it in systemctl

A pid can be recycled, but a pidfd is pinned. Add a new method that is safer
as it takes a pidfd as input.
Return not only the D-Bus object path, but also the unit id and the last
recorded invocation id, as they are both useful (especially the id, as
converting from a path object to a unit id from a script requires another
round-trip via D-Bus).

Note that the manager still tracks processes by pid, so theorethically this
is not fully error-proof, but on the other hand the method response is
synchronous and the manager is single-threaded, so once a call is being
processed the unit database will not change anyway. Once the manager
switches to use pidfds everywhere, this can be further hardened.
This commit is contained in:
Luca Boccassi
2023-01-18 10:58:46 +01:00
committed by Lennart Poettering
parent 9ca3bfb6c4
commit e0e7bc8223
5 changed files with 151 additions and 13 deletions
+1
View File
@@ -245,6 +245,7 @@ systemctl status "systemd-*.timer"
systemctl status "systemd-journald*.socket"
systemctl status "sys-devices-*-ttyS0.device"
systemctl status -- -.mount
systemctl status 1
# --marked
systemctl restart "$UNIT_NAME"