dbus: Add GetUnitByPID
This implements the org.freedesktop.systemd1.Manager.GetUnitByPID method from https://www.freedesktop.org/wiki/Software/systemd/dbus/
The test is a very rough outline - I couldn't get it to run locally. Any tips on that?
Thanks for the PR! Code looks mostly ok. I think that test is failing because you didn't specify an absolute path for the binary.
If path lookup gets too complex, you can try re-arranging the test so that it just runs a sleeping service. That way you can get the service by name, then lookup its main PID from properties, then use your method with the PID to get the path, and finally verify that it matches with the service property.
That way you can get the service by name, then lookup its main PID from properties, then use your method with the PID to get the path, and finally verify that it matches with the service property.
I'm having trouble looking up the pid from properties with GetUnitProperties or GetUnitProperty. Is it "MainPID" that I should be looking for?
@APTy yes, MainPID tells you the pid of the top-level process.
Got it, thanks. Do you happen to know if it's only available after certain versions of systemd? I tried using GetUnitProperty to look it up (and could find other properties like Id) but couldn't find MainPID. I can follow up with some repro steps but just wanted to check first
Ah, I got it - needed to use GetServiceProperty not GetUnitProperty, since MainPID is defined on the org.freedesktop.systemd1.Service interface, not org.freedesktop.systemd1.Unit.
Working through a final compatibility issue that seems to appear only on ubuntu:18.04 that results in:
expected
"/org/freedesktop/systemd1/unit/_2d_2eslice"
to equal
"/org/freedesktop/systemd1/unit/get_2dunit_2dpid_2eservice"
Seems like the call to GetUnitByPID() on 18.04 is returning the object path to the root slice configuration unit -.slice (http://manpages.ubuntu.com/manpages/bionic/man5/systemd.slice.5.html), looking into this more