Bug 417534 - Empty ~/.gtkrc-2.0 file is created every time I login
Summary: Empty ~/.gtkrc-2.0 file is created every time I login
Status: RESOLVED FIXED
Alias: None
Product: systemsettings
Classification: Applications
Component: kcm_style (show other bugs)
Version: 5.18.0
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-13 03:17 UTC by Guilherme Silva
Modified: 2023-11-04 01:35 UTC (History)
11 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.27.2
Sentry Crash Report:


Attachments
Patch for kde-gtk-config 5.18.5 (4.03 KB, patch)
2020-06-09 07:41 UTC, Guilherme Silva
Details
Patch for kde-gtk-config 5.19.80 (3.89 KB, patch)
2020-06-09 07:42 UTC, Guilherme Silva
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Guilherme Silva 2020-02-13 03:17:03 UTC
SUMMARY
I'm not sure if it's Plasma itself who's creating the file, but I'm pretty sure it started happening after I upgraded to 5.18.

This could be related to the fact that I have my gtkrc config file pointing elsewhere, using the GTK2_RC_FILES environment variable. So perhaps that is confusing Plasma... Not sure why ~/.gtkrc-2.0 is created as an empty file, though.

STEPS TO REPRODUCE
1. (Maybe) have GTK2_RC_FILES set to ~/.config/gtk-2.0/gtkrc
2. Delete the ~/.gtkrc-2.0 (if any)
3. Logout Plasma
4. Login

OBSERVED RESULT
An empty file named .gtkrc-2.0 will be created in your home directory

EXPECTED RESULT
No .gtkrc-2.0 in my home directory

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux
KDE Plasma Version: 5.18.0
KDE Frameworks Version: 5.67.0
Qt Version: 5.14.1
Comment 1 Guilherme Silva 2020-02-13 14:24:28 UTC
Probably related to this? https://phabricator.kde.org/D26261

I skimmed through the code a bit and noticed the GTK2 config path is hardcoded to ~/.gtkrc-2.0, plus there's no mention of GTK2_RC_FILES.
Comment 2 Mikhail Zolotukhin 2020-04-25 16:11:34 UTC
GTK daemon does not create empty .gtkrc-2.0 and respect GTK2_RC_FILES env variable. Something other is creating it. Could you still reproduce?
Comment 3 Bug Janitor Service 2020-05-10 04:33:16 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 4 aliceaccounts 2020-05-23 14:58:59 UTC
can repro on 5.18.5
Comment 5 Guilherme Silva 2020-06-09 03:38:57 UTC
Sorry I took this long to respond.

Yes, I can still reproduce this on Plasma 5.18.5.

A quick search for ".gtkrc-2.0" on KDE's org on Github showed me this file (specifically, the writeGtk2Settings() method):

https://github.com/KDE/plasma-workspace/blob/7f2ae10539f2167663aab713986e3f5e0528289f/gmenu-dbusmenu-proxy/menuproxy.cpp#L169

That method doesn't address the GTK2_RC_FILES variable, instead it hardcodes it to ~/.gtkrc-2.0. A bit down in the code, that method is called by writeGtk2Settings(), which I guess ends up creating a new (but empty) .gtkrc-2.0 in my home directory.

Just a wild guess, though. I'm not a C++ programmer but I'll try fixing it locally, and I'll let you guys know if that's what's causing the problem.

Thanks.
Comment 6 Guilherme Silva 2020-06-09 07:41:30 UTC
Created attachment 129153 [details]
Patch for kde-gtk-config 5.18.5

Actually, never mind my last e-mail. The real culprit is the kde-gtk-config daemon.

Once I:

- Disable its service ("Plasma GTKd") in Plasma's Background Services manager
- Remove the empty ~/.gtkrc-2.0 file
- And, finally, re-login, the file isn't created anymore.

So, brand new steps to reproduce:

1. Open the Background Services manager:
   $ kcmshell5 kcmkded
2. Search and disable "Plasma GTKd", hit OK.
3. Make sure there's no .gtkrc-2.0 file in your home folder.
4. Open the Background Services again, but now with GTK2_RC_FILES set:
   $ env GTK2_RC_FILES=/tmp/gtkrc kcmshell5 kcmkded
5. Re-enable the "Plasma GTKd" service, hit Apply.
6. There should be an empty .gtkrc-2.0 in your home now:
   $ file ~/.gtkrc-2.0
   /home/gui/.gtkrc-2.0: empty

I've fixed it locally (without any heavy testing, however) by removing some duplicated code and creating a method that will either respect GTK2_RC_FILES or fallback to ~/.gtkrc-2.0, if GTK2_RC_FILES isn't set or if it's empty.

I'm attaching two patches (they accomplish the same): The first one I made for kde-gtk-config v5.18.5 (the latest version on Arch), and the other one which I just rebased against commit 380bff1f (v5.19.80).

KDE Devs: Feel free to use it (or not), modify it, whatever. I'm reluctant to submit it for review, because I _really_ don't program in C++. So if did that and you guys' asked for modifications, I'd be wasting your time.

If the patch is ready to merge, awesome! If it's not, then I'm sorry.

And thank you for making Plasma so awesome. :)
Comment 7 Guilherme Silva 2020-06-09 07:42:13 UTC
Created attachment 129154 [details]
Patch for kde-gtk-config 5.19.80
Comment 8 vmarinescu 2020-08-12 13:36:14 UTC
BUMP. Any progress on merging/extending @Guilherme Silva's patch?
I also have this issue. 

Logs from .xsession-errors:
> kdeinit5: Got SETENV 'GTK_RC_FILES=/etc/gtk/gtkrc:/home/vlad/.gtkrc:/home/vlad/.config/gtk-1.0/gtkrc:/home/vlad/.config/gtkrc' from launcher.
> kdeinit5: Got SETENV 'GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/vlad/.gtkrc-2.0:/home/vlad/.config/gtk-2.0/gtkrc:/home/vlad/.config/gtkrc-2.0' from launcher.

However, only gtkrc-2.0 is created.

@Guilherme Silva, I am skeptical to disable GTKd background service. What does it do?  Also thank you for the patch.

----

Thank you to all KDE team. I love Plasma!
Comment 9 Alexandre 2021-05-19 20:22:46 UTC
I'm still getting this on `kde-gtk-config` 5.21.5, Wayland, Archlinux.
This bug is the only thing that keeps Plasma from being XDG-dirs compliant.
Comment 10 Rocket Aaron 2023-02-19 09:33:20 UTC
I think I've found the cause of this bug, see https://bugs.kde.org/show_bug.cgi?id=415770#c8
Comment 11 Fushan Wen 2023-02-25 14:48:56 UTC
Git commit af1cc78d96fdbb2ad9adbb27a37423201b9cc8c9 by Fushan Wen, on behalf of Rocket Aaron.
Committed on 25/02/2023 at 14:48.
Pushed by fusionfuture into branch 'master'.

Avoid creating gtkrc-2.0 if it does not exist

This MR would fix the following 2 bugs: Plasma does not follow `GTK2_RC_FILES` environment variable and would create `~/.gtkrc-2.0` every time on login.

---

Here is the more detailed explanation:

`gmenu-dbusmenu-proxy` hardcoded `gtkrcPath` as `QDir::homePath() + QLatin1String("/.gtkrc-2.0")`:

https://invent.kde.org/plasma/plasma-workspace/-/blob/v5.27.1/gmenu-dbusmenu-proxy/menuproxy.cpp#L163

but it's not creating the file if it's not present. `kde-gtk-config`'s `Gtk2ConfigEditor::removeLegacyStrings()` is the cause:

https://invent.kde.org/plasma/kde-gtk-config/-/blob/v5.27.1/kded/config_editor/gtk2.cpp#L54

it uses `Utils::readFileContents(QFile &file)`

https://invent.kde.org/plasma/kde-gtk-config/-/blob/v5.27.1/kded/config_editor/utils.cpp#L19

which calls `file.open(QIODevice::ReadWrite | QIODevice::Text)`, and the mode `ReadWrite` means to create the file if it's not exist:

https://doc.qt.io/qt-5/qfile.html#open

So at startup, `kde-gtk-config` launches and a empty `~/.gtkrc-2.0` file is created, then `gmenu-dbusmenu-proxy` watchs the file creation

https://invent.kde.org/plasma/plasma-workspace/-/blob/v5.27.1/gmenu-dbusmenu-proxy/menuproxy.cpp#L106

and write the content to the file.

Furthermore, even if `~/.gtkrc-2.0` does not exist, `Gtk2ConfigEditor::removeLegacyStrings()` would still write "modified" content to the file

https://invent.kde.org/plasma/kde-gtk-config/-/blob/v5.27.1/kded/config_editor/gtk2.cpp#L76

but in that case, it would just create an empty file, for `gmenu-dbusmenu-proxy` to watch and write something to it.
Related: bug 415770
FIXED-IN: 5.27.2

M  +3    -0    kded/config_editor/gtk2.cpp
M  +1    -1    kded/config_editor/utils.cpp

https://invent.kde.org/plasma/kde-gtk-config/commit/af1cc78d96fdbb2ad9adbb27a37423201b9cc8c9
Comment 12 Fushan Wen 2023-02-25 14:50:52 UTC
Git commit 85bfea563102e9a149c54ff420c78972387d73f7 by Fushan Wen, on behalf of Rocket Aaron.
Committed on 25/02/2023 at 14:49.
Pushed by fusionfuture into branch 'Plasma/5.27'.

Avoid creating gtkrc-2.0 if it does not exist

This MR would fix the following 2 bugs: Plasma does not follow `GTK2_RC_FILES` environment variable and would create `~/.gtkrc-2.0` every time on login.

---

Here is the more detailed explanation:

`gmenu-dbusmenu-proxy` hardcoded `gtkrcPath` as `QDir::homePath() + QLatin1String("/.gtkrc-2.0")`:

https://invent.kde.org/plasma/plasma-workspace/-/blob/v5.27.1/gmenu-dbusmenu-proxy/menuproxy.cpp#L163

but it's not creating the file if it's not present. `kde-gtk-config`'s `Gtk2ConfigEditor::removeLegacyStrings()` is the cause:

https://invent.kde.org/plasma/kde-gtk-config/-/blob/v5.27.1/kded/config_editor/gtk2.cpp#L54

it uses `Utils::readFileContents(QFile &file)`

https://invent.kde.org/plasma/kde-gtk-config/-/blob/v5.27.1/kded/config_editor/utils.cpp#L19

which calls `file.open(QIODevice::ReadWrite | QIODevice::Text)`, and the mode `ReadWrite` means to create the file if it's not exist:

https://doc.qt.io/qt-5/qfile.html#open

So at startup, `kde-gtk-config` launches and a empty `~/.gtkrc-2.0` file is created, then `gmenu-dbusmenu-proxy` watchs the file creation

https://invent.kde.org/plasma/plasma-workspace/-/blob/v5.27.1/gmenu-dbusmenu-proxy/menuproxy.cpp#L106

and write the content to the file.

Furthermore, even if `~/.gtkrc-2.0` does not exist, `Gtk2ConfigEditor::removeLegacyStrings()` would still write "modified" content to the file

https://invent.kde.org/plasma/kde-gtk-config/-/blob/v5.27.1/kded/config_editor/gtk2.cpp#L76

but in that case, it would just create an empty file, for `gmenu-dbusmenu-proxy` to watch and write something to it.
Related: bug 415770
FIXED-IN: 5.27.2


(cherry picked from commit af1cc78d96fdbb2ad9adbb27a37423201b9cc8c9)

M  +3    -0    kded/config_editor/gtk2.cpp
M  +1    -1    kded/config_editor/utils.cpp

https://invent.kde.org/plasma/kde-gtk-config/commit/85bfea563102e9a149c54ff420c78972387d73f7