Bug 490469

Summary: Applications started via custom shortcut do not have ICEAUTHORITY defined
Product: [Frameworks and Libraries] frameworks-kglobalaccel Reporter: Oliver Freyermuth <o.freyermuth>
Component: generalAssignee: kdelibs bugs <kdelibs-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: asturm, kdedev, natalie_clarius, nate
Priority: NOR    
Version: 5.116.0   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=488520
https://bugs.kde.org/show_bug.cgi?id=432975
Latest Commit: Version Fixed In: 6.1.0
Sentry Crash Report:

Description Oliver Freyermuth 2024-07-18 19:14:16 UTC
SUMMARY
KDE/Qt applications started via a user-defined shortcut do not have `ICEAUTHORITY` set in their environment and hence can not be session-restored. 

STEPS TO REPRODUCE
1. Go to "Custom Shortcuts" in system settings and add your own shortcut to start "konsole", e.g. "Alt+F2". 
2. Save and apply, then press the shortcut "Alt+F2". 

OBSERVED RESULT
The opened "konsole" is not session-restored. Starting other KDE/Qt applications from within, e.g. another "konsole", reveals the message:
```
Qt: Session management error: None of the authentication protocols specified are supported
```
Checking the environment:
```
$ echo $ICEAUTHORITY
$ echo $SESSION_MANAGER 
local/alien17:@/tmp/.ICE-unix/30501,unix/alien17:/tmp/.ICE-unix/30501
```
reveals `ICEAUTHORITY` is not defined, but `SESSION_MANAGER` is. 
A "konsole" started via the launcher or krunner has both variables set as expected. 

EXPECTED RESULT
`ICEAUTHORITY` to also be set for programmes started via custom shortcuts. 

SOFTWARE/OS VERSIONS
KDE Plasma Version: 5.27.11
KDE Frameworks Version: 5.116.0
Qt Version: 5.15.14

ADDITIONAL INFORMATION
using an X11 session with OpenRC. 

Note that this is not a duplicate of https://bugs.kde.org/show_bug.cgi?id=487912 , Gentoo has backported that patch to the distro package I am using, and not all programmes are affected.
Comment 1 TraceyC 2024-07-24 20:12:14 UTC
Thanks for the bug report. I'm not able to reproduce the bug with Kubuntu 24.04 on Plasma 5.27.11.
I'll leave this open in case someone else can reproduce it.

https://bugs.kde.org/show_bug.cgi?id=488520 seems related as it was reported against 5.27.11 on Gentoo

Note: $ICEAUTHORITY was not defined even if konsole was started via the Kickoff menu or the taskbar icon.
Desktop Session setting was set to restore apps open "On last logout"

STEPS TO REPRODUCE
1. Created a custom shortcut for konsole
2. Started konsole with the custom shortcut
3. Logged out and back in
  OBSERVED RESULT
  The konsole window was restored in the same position it was when I logged out

4. Entered "konsole" into the terminal to start a new terminal. Also tried kate.
  OBSERVED RESULT
  No session management error

I'll leave this open in case someone else can reproduce it.

Operating System: Kubuntu 24.04
KDE Plasma Version: 5.27.11
KDE Frameworks Version: 5.115.0
Qt Version: 5.15.13
Kernel Version: 6.8.0-38-generic (64-bit)
Graphics Platform: X11
Processors: 2 × 11th Gen Intel® Core™ i7-11800H @ 2.30GHz
Memory: 3.8 GiB of RAM
Graphics Processor: llvmpipe
Manufacturer: QEMU
Product Name: Standard PC (Q35 + ICH9, 2009)
System Version: pc-q35-8.2
Comment 2 Oliver Freyermuth 2024-07-24 21:50:26 UTC
Thanks for checking! 

I delved into this and can explain why KUbuntu does not appear to be affected:
They did not fetch the new patch release 5.27.11.1 of plasma-workspace completely, but only backported parts of it. 
Hence, they do not carry https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4382 in full. 

For that reason, Ubuntu does not use a pattern such as:
/run/user/1000/iceauth_someRandomString
for their ICE auth files, but just the default:
/run/user/1000/ICEauthority
Hence, it works without the variable being defined due to the fallback to the "default name". 
Note that the MR I linked above also added the corresponding code to ksmserver to set that variable, which explains why Ubuntu misses that, as they did not pull in the full MR / did not pull 5.27.11.1 completely. 

So it appears that to reproduce that, 5.27.11.1 must be used, while 5.27.11 is not affected. 
Sadly, Plasma itself did not report the ".1" version and the bug tracker does not allow to select it, so I did not include this critical detail in my report. 

Do you have the chance to re-test with 5.27.11.1?
Comment 3 Nate Graham 2024-07-26 22:53:41 UTC
I'm afraid "Custom Shortcuts" has been removed in Plasma 6. It was also unmaintained for 7 years before that, so any bugfixes for it are unlikely.

Can you re-create your shortcut using the "Shortcuts" page in System Settings? Just add a new shortcut to the existing Konsole entry. Does the issue still happen?
Comment 4 Oliver Freyermuth 2024-07-27 04:06:29 UTC
Thanks Nate, I was indeed unaware that "Custom Shortcuts" was deprecated and removed, good to know and understandable. 

I created a new shortcut via the "Shortcuts" page for Konsole, and can sadly confirm it is affected by the same issue. 

It even has two more issues:
* It starts up with both "ICEAUTHORITY" and "SESSION_MANAGER" being unset, so it does not even complain that session management does not work, but just does not try it. Via "Custom Shortcuts"; at least "SESSION_MANAGER" was set. 
* It starts up in "/" instead of my home directory (not sure how to change that, only happens when Konsole is started via "Shortcuts"), which makes it quite cumbersome for day-to-day usage.
Comment 5 Nate Graham 2024-07-29 20:31:39 UTC
Thanks for testing that.

The fact that it starts up in / rather than your homedir seems suspicious. Have yo made any user or system level customizations that could explain this?
Comment 6 Oliver Freyermuth 2024-07-30 07:19:16 UTC
(In reply to Nate Graham from comment #5)
> The fact that it starts up in / rather than your homedir seems suspicious.
> Have yo made any user or system level customizations that could explain this?

No, that also happens on fresh installs of Gentoo. Digging a bit more, this seems to be a common issue with processes forking off from kglobalaccel5 affecting other users, too:
https://discuss.kde.org/t/konsole-and-others-starts-in-root-dir/4466/22
I can confirm the last statement there from my system:
Using OpenRC (not systemd), SDDM and rootful X11 starts dbus-launch with / as working directory, which is inherited by kglobalaccel5, which is then inherited by Konsole or other things started via "Shortcut". 

Should I create a separate issue on this? 
Note that kglobalaccel5 and hence also Konsole started via "Shortcut" is missing both SESSION_MANAGER and ICEAUTHORITY in its environment, so even if the working directory issue is left aside, the issue at hand still applies.
Comment 7 Andreas Sturmlechner 2024-07-30 20:20:45 UTC
(In reply to Nate Graham from comment #3)
> I'm afraid "Custom Shortcuts" has been removed in Plasma 6. It was also
> unmaintained for 7 years before that, so any bugfixes for it are unlikely.
That's not good news for Plasma 5 users where this is supposed to work.

(In reply to Oliver Freyermuth from comment #6)
> (In reply to Nate Graham from comment #5)
> > The fact that it starts up in / rather than your homedir seems suspicious.
> > Have yo made any user or system level customizations that could explain this?
See also bug 432975
Comment 8 Nate Graham 2024-07-31 18:30:14 UTC
432975 indeed seems heavily related. Possibly both issues have the same root cause.
Comment 9 Oliver Freyermuth 2024-09-20 18:49:24 UTC
After an upgrade to Plasma 6.1, I can not reproduce both of the related issues anymore (i.e. of course this issue here is gone, since custom shortcuts were removed, but luckly, also the "/ path" issue seems fixed using "Shortcuts". 

I'm not sure whether all the cases in the related issue 432975 have been fixed, though, but for me this makes Shortcuts usable again with 6.1! :-)
Comment 10 Nate Graham 2024-09-22 00:28:47 UTC
Cool, let's call this one fixed at least!