go-systemd icon indicating copy to clipboard operation
go-systemd copied to clipboard

dbus: add GetUnitProcessesContext to list any unit's running processes

Open pphysch opened this issue 4 years ago • 3 comments

This PR adds a binding for org.freedesktop.systemd1.Manager.GetUnitProcesses, taking a unit string and returning a list of all processes currently running under that unit (including child units).

This is convenient for getting a lot of information about a Slice's running processes, as it descends into child Slices/Scopes and includes those processes in the list. For example, if we target user-1000.slice we can learn about the different session-* Scopes under that user and all the processes therein.

My test (which may need adjustments to be more idiomatic/isolated) passes on systemd v239 (RHEL 8), but this Manager method doesn't exist on v219 (RHEL 7). I dug for a bit and can't find the exact version that implemented the GetProcesses API, but it seems to have been around 5 years ago.

This is my first PR here so please let me know how I can fix it! I used existing Manager method bindings as a template, so the code itself should be conformant even if the test needs work.

pphysch avatar Sep 20 '21 17:09 pphysch

Thanks for the PR! It looks like the new test is frequently failing in CI, I think because it is internally racing (see review).

lucab avatar Sep 21 '21 09:09 lucab

Looks like the test is still failing even with delayed retries; I'll rewrite it so that it does more mocking and has less reliance on the system/container.

pphysch avatar Sep 21 '21 17:09 pphysch

Any chance this PR can get reviewed? Tests were passing as of the last commit.

pphysch avatar Mar 08 '23 18:03 pphysch