Bug 455252

Summary: Applications with malformed .desktop files do not autostart with systemd boot
Product: [Plasma] plasmashell Reporter: wolfyrion <kyriacos>
Component: Startup processAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: hsantanna, kde, nate, phd, sky.not.a.bot
Priority: VHI Keywords: regression
Version: 5.25.0   
Target Milestone: 1.0   
Platform: Other   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=427340
https://bugs.kde.org/show_bug.cgi?id=455889
Latest Commit: Version Fixed In: Plasma 5.26 with Frameworks 5.99 and systemd 252
Attachments: the desktop generates log error and the app will not be autostarted

Description wolfyrion 2022-06-14 14:07:17 UTC
SUMMARY
 KDE does not auto-start applications - getting this error..
***
Jun 14 16:42:05 xWx systemd-xdg-autostart-generator[1322]: /home/wolfyrion/.config/autostart/org.kde.latte-dock.desktop:9: Unknown key name 'InitialPreference' in section 'Desktop Entry', ignoring.
Jun 14 16:42:05 xWx systemd-xdg-autostart-generator[1322]: /home/wolfyrion/.config/autostart/org.kde.latte-dock.desktop:17: Unknown key name 'TerminalOptions' in section 'Desktop Entry', ignoring.
Jun 14 16:42:05 xWx systemd-xdg-autostart-generator[1322]: Configuration file /home/wolfyrion/.config/autostart/xdotool.desktop is marked executable. Please remove executable permission bits. Proceeding anyway.
Jun 14 16:42:05 xWx systemd-xdg-autostart-generator[1322]: /home/wolfyrion/.config/autostart/xdotool.desktop:15: Unknown key name 'TerminalOptions' in section 'Desktop Entry', ignoring.
Jun 14 16:42:05 xWx systemd-xdg-autostart-generator[1322]: /home/wolfyrion/.config/autostart/cadence.desktop:1: Unknown section 'Carla Shortcut Group'. Ignoring.
Jun 14 16:42:05 xWx systemd-xdg-autostart-generator[1322]: /home/wolfyrion/.config/autostart/cadence.desktop:6: Unknown section 'CarlaControl Shortcut Group'. Ignoring.
Jun 14 16:42:05 xWx systemd-xdg-autostart-generator[1322]: /home/wolfyrion/.config/autostart/cadence.desktop:11: Unknown section 'Catia Shortcut Group'. Ignoring.
Jun 14 16:42:05 xWx systemd-xdg-autostart-generator[1322]: /home/wolfyrion/.config/autostart/cadence.desktop:16: Unknown section 'Claudia Shortcut Group'. Ignoring.
Jun 14 16:42:05 xWx systemd-xdg-autostart-generator[1322]: /home/wolfyrion/.config/autostart/cadence.desktop:21: Unknown section 'ClaudiaLauncher Shortcut Group'. Ignoring

NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***


STEPS TO REPRODUCE
1.  just add latte to autostart
2. 
3. 

OBSERVED RESULT


EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: Arch
(available in About System)
KDE Plasma Version: 5.25.0
KDE Frameworks Version: 5.95.0
Qt Version: 5.15.4

ADDITIONAL INFORMATION
Comment 1 Nate Graham 2022-06-14 18:12:02 UTC
Possibly caused by the systemd boot which we turned on by default in 5.25.

You can verify by turning it off with `kwriteconfig5 --file startkderc --group General --key systemdBoot false` and then rebooting. Does that fix it?
Comment 2 wolfyrion 2022-06-14 18:25:32 UTC
(In reply to Nate Graham from comment #1)
> Possibly caused by the systemd boot which we turned on by default in 5.25.
> 
> You can verify by turning it off with `kwriteconfig5 --file startkderc
> --group General --key systemdBoot false` and then rebooting. Does that fix
> it?

yes thank you very much it fix it! :)
Comment 3 Nate Graham 2022-06-14 18:44:33 UTC
Thanks.
Comment 4 David Edmundson 2022-06-14 19:01:01 UTC

Can I have the full wolfyrion/.config/autostart/cadence.desktop

As well as output of `journalctl --user -b` from a reboot with the broken behaviour re-enabled.
Comment 5 David Edmundson 2022-06-15 05:59:27 UTC
Marking as needsinfo. I was unable to reproduce any issue locally.
Comment 6 David Edmundson 2022-06-17 08:43:16 UTC
I still need this information, we've taken the time to help you suppress the problem but we still need to fix it properly for other users.
Comment 7 Henrique Sant'Anna 2022-06-23 18:51:46 UTC
I'm affected by this bug too. I have 6 apps set to autostart, but only one is currrently starting (Yakuake).

X11 plasma session.
from `journalctl -b` I can see this:

`
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: /home/henrique/.config/autostart/copyq.desktop:181: Invalid value for boolean: False
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: /home/henrique/.config/autostart/copyq.desktop:181: Failed to parse file: Invalid argument
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: Failed to parse /home/henrique/.config/autostart/copyq.desktop, ignoring it
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: /home/henrique/.config/autostart/insync.desktop:15: Unknown key name 'TerminalOptions' in section 'Desktop Entry', ignoring.
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: /home/henrique/.config/autostart/org.kde.latte-dock.desktop:43: Unknown key name 'InitialPreference' in section 'Desktop Entry', ignoring.
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: Configuration file /home/henrique/.config/autostart/org.kde.yakuake.desktop is marked executable. Please remove executable permission bits. Proceeding anyway.
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: /home/henrique/.config/autostart/org.kde.yakuake.desktop:163: Unknown key name 'TerminalOptions' in section 'Desktop Entry', ignoring.
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: Configuration file /home/henrique/.config/autostart/telegramdesktop.desktop is marked executable. Please remove executable permission bits. Proceeding anyway.
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: /home/henrique/.config/autostart/telegramdesktop.desktop:18: Unknown key name 'TerminalOptions' in section 'Desktop Entry', ignoring.
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: Configuration file /home/henrique/.config/autostart/goldendict.desktop is marked executable. Please remove executable permission bits. Proceeding anyway.
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: /home/henrique/.config/autostart/goldendict.desktop:16: Unknown key name 'TerminalOptions' in section 'Desktop Entry', ignoring.
`
Comment 8 Henrique Sant'Anna 2022-06-23 19:04:40 UTC
Created attachment 150104 [details]
the desktop generates log error and the app will not be autostarted

jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: /home/henrique/.config/autostart/copyq.desktop:181: Invalid value for boolean: False
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: /home/henrique/.config/autostart/copyq.desktop:181: Failed to parse file: Invalid argument
jun 23 15:30:17 anarch systemd-xdg-autostart-generator[1518]: Failed to parse /home/henrique/.config/autostart/copyq.desktop, ignoring it
Comment 9 Nate Graham 2022-06-23 19:08:35 UTC
Those look like valid errors to me; seems like your autostarted apps' .desktop files are malformed and can't be parsed.

It might be good to bubble up this error in the UI somewhere, but ultimately the solution there is for those malformed files to be fixed.
Comment 10 David Edmundson 2022-06-23 20:16:02 UTC
181: Hidden=False


spec says: " Values of type boolean must either be the string true or false. "
xdg generator must be case sensitive, KDE's isn't.

It is pretty extreme to fail rather than just ignore the relevant entry. I can maybe change that upstream.

I can go through any other broken desktop files. Though I'm sure it'll all come down to stricter spec compliance.
Comment 11 Nate Graham 2022-06-24 14:13:06 UTC
Changing the parser to be less strict might make sense, but regardless, we should show these errors to the user, probably in the autostart KCM. That way they can see what's going on and figure out what to do about it, or at least whose fault it might be. For that, I have filed Bug 455889.
Comment 12 David Edmundson 2022-06-24 14:24:39 UTC
And I'll close this
Comment 13 Nate Graham 2022-06-24 14:41:22 UTC
I don't think RESOLVED NOT A BUG is the correct resolution. Apps not auto-starting as expected is definitely a bug, and showing the errors to the user doesn't change that.

We can say it's a bug in the XDG parser being too strict, in which case it's RESOLVED UPSTREAM. Or we can say it's a bug in the specific apps having malformed desktop files, in which case it's RESOLVED DOWNSTREAM.

Which one shall it be?
Comment 14 Henrique Sant'Anna 2022-06-24 17:35:55 UTC
I suggest that for every ".desktop" file that cannot be auto-started, a notification be generated for the user, so that the user knows that that specific application could not be started automatically.

Furthermore, it is important that in the configuration screen for automatic startup it is clear to the user which of the listed applications will never be started and, if possible, for what reason.

Waiting for users to realize for themselves that a certain application did not start when it should and that after that they have to investigate in the logs why the application was not started, does not seem to me to be an desirable behavior.

Therefore, I consider that this is a bug, whatever the solution that is developed to fix it.
Comment 15 Henrique Sant'Anna 2022-06-24 18:12:23 UTC
The "TerminalOptions=" parameter, which makes ".desktop" files invalid, is added by Plasma.
To reproduce:
     In the startup and shutdown settings click on Properties for any listed application, then enter the Application tab of the properties window, edit the command line and then press the OK button.
    
As a result, the ".desktop" file now has the invalid parameter "TerminalOptions=" which prevents the application from auto-starting.
Comment 16 Nate Graham 2022-06-24 18:24:59 UTC
(In reply to Henrique Sant'Anna from comment #14)
> I suggest that for every ".desktop" file that cannot be auto-started, a
> notification be generated for the user, so that the user knows that that
> specific application could not be started automatically.
> 
> Furthermore, it is important that in the configuration screen for automatic
> startup it is clear to the user which of the listed applications will never
> be started and, if possible, for what reason.
> 
> Waiting for users to realize for themselves that a certain application did
> not start when it should and that after that they have to investigate in the
> logs why the application was not started, does not seem to me to be an
> desirable behavior.
> 
> Therefore, I consider that this is a bug, whatever the solution that is
> developed to fix it.
Yes, that's what bug 455889 is all about.
Comment 17 Nate Graham 2022-06-24 18:26:17 UTC
(In reply to Henrique Sant'Anna from comment #15)
> The "TerminalOptions=" parameter, which makes ".desktop" files invalid, is
> added by Plasma.
> To reproduce:
>      In the startup and shutdown settings click on Properties for any listed
> application, then enter the Application tab of the properties window, edit
> the command line and then press the OK button.
>     
> As a result, the ".desktop" file now has the invalid parameter
> "TerminalOptions=" which prevents the application from auto-starting.

Can you please file a new bug report about that specifically, and paste the link to it here? Thanks!
Comment 18 nightBulb 2022-08-28 16:45:31 UTC
I too faced this issue with ssh-add

[Desktop Entry]
Exec=ssh-add -q /home/username/.ssh/id_rsa_some_key

The .desktop file now requires full path, and does not recognize ( "~" / tilde character ) for home

i.e 
Exec=ssh-add -q ~/.ssh/id_rsa_some_key
does not work.

(Just documenting this path issue somewhere)
Comment 19 phd 2022-09-10 13:05:43 UTC
I just updated to Plasma 2.25 (2.25.5) from backports-extra repository and this issue hit me.

Yes, `kwriteconfig5 --file startkderc --group General --key systemdBoot false` fixes it.

But I think this is still a KDE bug and should be reopened.
Why?
Those files in ~/.config/autostart were generated by previous versions of KDE, and they worked perfectly fine.
Now after the update they just stopped working.
So it's a KDE bug that breaks users' desktops heavily. *Something* should be done about it.

1. Can those files be automatically fixed if they are not valid .desktop files?

2. Can the files that fail to run using the new systemd boot method be detected?
And can they be handled by the KDE startup process and actually *run* using the old way?

Side note:
Running .desktop file commands like `sleep 3 && something` used to work fine, and now it doesn't.
It would be nice to still have support for that.
Comment 20 phd 2022-09-10 13:07:55 UTC
*Plasma 5.25
Comment 21 Nate Graham 2022-09-12 19:37:52 UTC
I have to agree.

From the Plasma user's perspective, something that was working that was under KDE's control broke. The fact that it broke because under the hood, Plasma switched to a different technical system that has stricter parsing requirements doesn't make it not Plasma's bug. Plasma chose to make that change and thus owns any regressions stemming from it.

So have two options:
1. Patch Plasma by reformatting now-invalid desktop files to be valid, in which case it remains our bug to fix. Changing anything with `=False` to be `=false` should hopefully not be that hard.
2. Patch systemd-xdg-autostart-generator to not be so strict, in which case it will be an upstream bug, but we should really submit the fix since we're affected by it.

We can do one or both, I don't think we have the option to do neither and call it not a bug.
Comment 22 David Edmundson 2022-09-13 08:26:23 UTC
>1. Patch Plasma by reformatting now-invalid desktop files to be valid

Most the malformed desktop files come from hand-written users. 

The problem with any migration after-the-fact is that by the time this lands all affected users would have fixed their desktop files anyway.
If this had been reported in the year when systemd was exclusively opt-in I'd have a different attitude but now it's in diminishing returns if there's any at all.

>2. Patch systemd-xdg-autostart-generator to not be so strict

There's a few separate issues discussed here. 
 - false/False. I reckon upstream would accept a fix for that. Worth a go.
 - "~" expansion. This is 50/50. The spec doesn't explicitly say it'll expand.
 - Invalid Exec lines. This would definitely be rejected upstream. It's not systemd doing stricter parsing, it's KDE doing something additional and yolo.

>I don't think we have the option to do neither and call it not a bug.

I will try the above two changes in systemd. I can change kmenuedit to be clearer on the Exec line. We can leave 455889 open. 
After that I don't think we have any sensible option on this bug other than to close it as downstream.
Comment 23 nightBulb 2022-09-13 10:21:19 UTC
(In reply to nightBulb from comment #18)
> I too faced this issue with ssh-add
> 
> [Desktop Entry]
> Exec=ssh-add -q /home/username/.ssh/id_rsa_some_key
> 
> The .desktop file now requires full path, and does not recognize ( "~" /
> tilde character ) for home
> 
> i.e 
> Exec=ssh-add -q ~/.ssh/id_rsa_some_key
> does not work.
> 
> (Just documenting this path issue somewhere)

Just to be clear I was following instructions from Arch Wiki (for Kubuntu):

https://wiki.archlinux.org/title/KDE_Wallet#:~:text=so%20auto_start%20force_run-,Using%20the%20KDE%20Wallet%20to%20store%20ssh%20key%20passphrases,-Note%3A%20An

Which suggests the short path (~), I have not yet edited Arch Wiki instructions as I was hoping more experienced devs might have better recommendation.
Comment 24 nightBulb 2022-09-13 10:24:55 UTC
As in I am running KDE Ubuntu 22.04, but, I was following instructions from Arch Wiki (my usual goto for Linux instructions/knowledge).
Comment 25 Bug Janitor Service 2022-09-13 10:48:00 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kmenuedit/-/merge_requests/10
Comment 26 David Edmundson 2022-09-13 12:12:49 UTC
Systemd false/False: https://github.com/systemd/systemd/pull/24656 handling
Comment 27 Nate Graham 2022-09-13 14:02:03 UTC
Nice! With those two plus ~ expansion (ideally), I think we could call this fixed, and then Bug 455889 could be a further enhancement.
Comment 28 Nate Graham 2022-09-13 14:57:41 UTC
(In reply to nightBulb from comment #23)
> Just to be clear I was following instructions from Arch Wiki (for Kubuntu):
> 
> https://wiki.archlinux.org/title/KDE_Wallet#:~:
> text=so%20auto_start%20force_run-,
> Using%20the%20KDE%20Wallet%20to%20store%20ssh%20key%20passphrases,-
> Note%3A%20An
> 
> Which suggests the short path (~), I have not yet edited Arch Wiki
> instructions as I was hoping more experienced devs might have better
> recommendation.

Seems like that should be edited to not recommend using a tilde in place of /home/[user], yeah.
Comment 29 David Edmundson 2022-09-13 14:58:50 UTC
Tilde expansion upstream https://github.com/systemd/systemd/pull/24658
Comment 30 David Edmundson 2022-09-14 15:17:42 UTC
Git commit 87c38a30fff27e3e9c0375f5c17d53ab0644ea0f by David Edmundson.
Committed on 13/09/2022 at 13:56.
Pushed by davidedmundson into branch 'master'.

Split single command entry box into separate program and arguments.

The desktop entry "Exec" states:
"A command line consists of an executable program optionally followed by
one or more arguments."

By having a single entry "command" encourages users to write shell
commands like "FOO=123 someApp" rather than a legal "/bin/env FOO=123
someApp".

This patch adopts the pattern used in kdevelop/hotspot/tools where we
explictly ask for executable and arguments.

M  +43   -22   basictab.cpp
M  +4    -2    basictab.h

https://invent.kde.org/plasma/kmenuedit/commit/87c38a30fff27e3e9c0375f5c17d53ab0644ea0f
Comment 31 Nate Graham 2022-09-14 15:21:34 UTC
bool tolerance was merged too. Now we just need https://github.com/systemd/systemd/pull/24658 and this is effectively fixed.
Comment 32 Nate Graham 2022-09-14 19:37:05 UTC
...Oh and also changing the UI in the Properties window.
Comment 33 Bug Janitor Service 2022-09-15 14:36:58 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/976
Comment 34 Nate Graham 2022-09-15 19:00:57 UTC
https://github.com/systemd/systemd/pull/24658 was merged. Now we're just waiting for https://invent.kde.org/frameworks/kio/-/merge_requests/976.
Comment 35 Nate Graham 2022-09-15 19:21:10 UTC
Git commit a85d3a5fe40c3d900067633d59a9a5b1e02e0eff by Nate Graham, on behalf of David Edmundson.
Committed on 15/09/2022 at 19:01.
Pushed by ngraham into branch 'master'.

KPropertiesDialog: Split single command entry box into separate exec and args

The desktop entry "Exec" states:
"A command line consists of an executable program optionally followed by
one or more arguments."

By having a single entry "command" encourages users to write shell
commands like "FOO=123 someApp" rather than a legal "/bin/env FOO=123
someApp". This happens to work for things launched by KIO but it is not
universal and leads to breakages in cross desktop code.

This patch adopts the pattern used in kdevelop/hotspot/tools where we
explicitly ask for executable and arguments.

M  +25   -6    src/widgets/kpropertiesdesktopbase.ui
M  +23   -6    src/widgets/kpropertiesdialog.cpp

https://invent.kde.org/frameworks/kio/commit/a85d3a5fe40c3d900067633d59a9a5b1e02e0eff
Comment 36 Nate Graham 2022-09-15 19:40:43 UTC
...aaaaand we're done!