Bug 389144 - libkworkspace: logind instantly kills all user sessions on shutdown
Summary: libkworkspace: logind instantly kills all user sessions on shutdown
Status: RESOLVED WORKSFORME
Alias: None
Product: ksmserver
Classification: Plasma
Component: general (show other bugs)
Version: 5.11.95
Platform: Other Linux
: NOR major
Target Milestone: ---
Assignee: Lubos Lunak
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-18 09:03 UTC by Max Harmathy
Modified: 2022-12-10 05:18 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Max Harmathy 2018-01-18 09:03:52 UTC
There is a severe problem with session handling on systems with logind.
This is reproducible on current kde-neon. 

Whenever a user on logout request a reboot or poweroff the KSMServer will use "KDisplayManager" (plasma-workspace/libkworkspace) to handle the request. On most current linux systems this will be handed to logind (not the display manager as the name might suggest) via DBus to "org.freedesktop.login1" by calling one of "org.freedesktop.login1.Manager.Reboot()" or "org.freedesktop.login1.Manager.PowerOff()".

logind will then kill *all* user sessions instantly. In particular the current running user session will not cleanly shutdown.

This can be illustrated by adding to "/usr/bin/startkade" after the comment "#Anything after here is logout/shutdown":

echo "Checkpoint" >> ~/startkde.log

This will be executed on simple logout, but not on a shutdown. In particular any following code is dead code on shutdown.
Comment 1 Kai Uwe Broulik 2018-01-18 11:52:30 UTC
So the issue sit hat KSMServer in its destructor calls KDisplayManager shutdown which will kill the session instantly. I was just digging forever to find where that would be, I thought requestShutdown would already just call logind.

How about using shutdown scripts? Does it work when you place a script in /etc/xdg/plasma-workspace/shutdown
Comment 2 Max Harmathy 2018-01-18 15:22:53 UTC
(In reply to Kai Uwe Broulik from comment #1)
> So the issue sit hat KSMServer in its destructor calls KDisplayManager
> shutdown which will kill the session instantly. I was just digging forever
> to find where that would be, I thought requestShutdown would already just
> call logind.

This happens in the class SystemdSession in

https://cgit.kde.org/plasma-workspace.git/tree/libkworkspace/kdisplaymanager.cpp

> How about using shutdown scripts? Does it work when you place a script in
> /etc/xdg/plasma-workspace/shutdown

Yes, scripts in /etc/xdg/plasma-workspace/shutdown get always executed. But they are executed by the KSMServer itself (although the documentation in plasma-desktop states they would be executed by startkde) and therefore before the DBus message to logind.

See KSMServer::runShutdownScripts in

https://cgit.kde.org/plasma-workspace.git/tree/ksmserver/server.cpp
Comment 3 Kai Uwe Broulik 2018-01-18 15:50:58 UTC
So, what prevents you from using shutdown scripts instead? There's not much going on in startkde after ksmserver has quit.

I agree this is a bug but requires significant re-engineering of the startup and session handling code that is decades old and probably becomes obsolete with Wayland anyway.

> although the documentation in plasma-desktop states they would be executed by startkde

Where can I find this documentation?
Comment 4 Max Harmathy 2018-01-18 18:43:24 UTC
(In reply to Kai Uwe Broulik from comment #3)
> So, what prevents you from using shutdown scripts instead? There's not much
> going on in startkde after ksmserver has quit.

Then the code following ksmserver in startkde should probably be moved to a shutdown script itself.

As for our specific use case: We will find a solution (probably not upstream suitable), that won't require too much refactoring on our side. But that should not be an issue for this ticket.

> I agree this is a bug but requires significant re-engineering of the startup
> and session handling code that is decades old and probably becomes obsolete
> with Wayland anyway.

Well with wayland there is "startplasmacompositor" which starts "kwin" which starts "startplasma" which is more or less a copy of "startkde". Thus basically there is the same problem for now. Or are there plans to replace ksmserver?

> > although the documentation in plasma-desktop states they would be executed by startkde
> 
> Where can I find this documentation?

I guess I got confused by the comment of Autostart::load in
https://cgit.kde.org/plasma-desktop.git/tree/kcms/autostart/autostart.cpp

That is probably just a copy and paste slip. The autostart documentation correctly only states that "$HOME/.config/plasma-workspace/env" is executed by "startkde". 
  
https://cgit.kde.org/plasma-desktop.git/tree/doc/kcontrol/autostart/index.docbook
Comment 5 Justin Zobel 2022-11-10 22:32:20 UTC
Thank you for reporting this issue in KDE software. As it has been a while since this issue was reported, can we please ask you to see if you can reproduce the issue with a recent software version?

If you can reproduce the issue, please change the status to "REPORTED" when replying. Thank you!
Comment 6 Bug Janitor Service 2022-11-25 05:21:28 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 7 Bug Janitor Service 2022-12-10 05:18:12 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!