needrestart icon indicating copy to clipboard operation
needrestart copied to clipboard

RFC: better `systemd --user` integration

Open intelfx opened this issue 1 year ago • 2 comments

Right now, processes running under systemd --user confuse needrestart in several ways:

  1. for processes that did not double-fork, needrestart considers systemd --user as the logical parent (which means that needrestart will bogusly report systemd itself as the process that needs to be restarted);
  2. when the systemd --user instance itself needs a restart, needrestart won't do anything about it;
  3. if the process to be restarted is a user service under systemd --user (as opposed to an arbitrary process started in a user scope), needrestart won't use this information in any way.

This PR offers a clean solution for (1) by disregarding the parent if it is a systemd --user instance (implemented via matching the cgroup of the parent against /init.scope$), and pretty hacky solutions for (2) and (3) (hence the RFC status).

intelfx avatar Apr 19 '24 03:04 intelfx

Can this be useful for #289?

Vladimir-csp avatar May 29 '24 12:05 Vladimir-csp

@Vladimir-csp yes, I believe it can. This needs a bit more UI work (the code I wrote piggybacks on existing data structures used for raw session processes, so it does not offer to perform a systemctl --user restart), but in principle this code already performs detection of user services which is what you ask for.

intelfx avatar May 29 '24 21:05 intelfx

@liske ping, is there any chance this PR could get reviewed? There has been a new release since this PR was posted, so I'm assuming there must be some sort of problem with this code specifically?

intelfx avatar Nov 20 '24 10:11 intelfx

@liske ping, is there any chance this PR could get reviewed? There has been a new release since this PR was posted, so I'm assuming there must be some sort of problem with this code specifically?

Sorry the security fixes for 3.8 have taken some time over the last few weeks and I was not able to take time for this more complex issue, yet. Scheduling it for the next release.

liske avatar Nov 20 '24 10:11 liske

Thanks. I just wanted to make sure this PR would actually be desired before I rebase it on top of the new changes.

intelfx avatar Nov 20 '24 10:11 intelfx

Systemd-managed user sessions with apps in units were already a reality in Gnome and at least some other major DEs.

I helped a bit to make it happen in independent compositors also.

Vladimir-csp avatar Nov 20 '24 15:11 Vladimir-csp

I need to reschedule this for 3.10. Needrestart 3.9 will be release ASAP to fix the regression reported in #317.

liske avatar Nov 24 '24 11:11 liske

I did a first review and it looks almost good to me. Are you going to remove the trace() functions in the restart.d scripts? I'm fine with the solution you implemented in ac804df3953429a3aee6d3f2bffd30c24f166851.

liske avatar Mar 24 '25 20:03 liske

Are you going to remove the trace() functions in the restart.d scripts?

Oh. I left it in by accident. Although, now that I look at it again, I should probably change it to kill the user manager with SIGRTMIN+25 — this is more portable than systemctl -M [email protected] syntax.

intelfx avatar Mar 24 '25 20:03 intelfx

Are you going to remove the trace() functions in the restart.d scripts?

Oh. I left it in by accident. Although, now that I look at it again, I should probably change it to kill the user manager with SIGRTMIN+25 — this is more portable than systemctl -M [email protected] syntax.

Thanks! So this PR (and #302) can now be merged? Just asking due to the RFC: in the PR title ;)

liske avatar Mar 26 '25 05:03 liske

Thanks!

liske avatar Mar 26 '25 21:03 liske