]> git.ipfire.org Git - thirdparty/systemd.git/commit
core: add GetUnitByPIDFD method and use it in systemctl
authorLuca Boccassi <bluca@debian.org>
Mon, 16 Jan 2023 23:46:01 +0000 (23:46 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 18 Jan 2023 09:58:46 +0000 (10:58 +0100)
commite0e7bc8223c3f28fcb48db9f0f003d9f03ca46d7
treeb4cd11a3508c2ec92080472aa7ca4391c8ff138a
parent9ca3bfb6c4d281bd047659b2891b5ac51c79ab34
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.
man/org.freedesktop.systemd1.xml
src/core/dbus-manager.c
src/core/org.freedesktop.systemd1.conf
src/systemctl/systemctl-show.c
test/units/testsuite-26.sh