Bug 415770 - Environment variable 'GTK2_RC_FILES' is ignored
Summary: Environment variable 'GTK2_RC_FILES' is ignored
Status: RESOLVED FIXED
Alias: None
Product: systemsettings
Classification: Applications
Component: kcm_gtk (show other bugs)
Version: 5.17.4
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Aleix Pol
URL:
Keywords:
: 417090 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-01-01 17:38 UTC by Guilherme Silva
Modified: 2023-02-25 14:51 UTC (History)
7 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.27.2


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Guilherme Silva 2020-01-01 17:38:18 UTC
SUMMARY
The kcm_gtk system component currently ignores the GTK2_RC_FILES environment variable and hardcodes reading/writing to ~/.gtkrc-2.0. I personally have the GTK2_RC_FILES variable set to $XDG_CONFIG_HOME/gtk-2.0/gtkrc in order to avoid cluttering my home directory.

STEPS TO REPRODUCE
1. Open the terminal.
2. Backup your current ~/.gtkrc-2.0: (Don't forget to restore it afterwards! :)
> mv ~/.gtkrc-2.0 ~/.gtkrc-2.0.bak
3. Point GTK2_RC_FILES to your backup file:
> export GTK2_RC_FILES=~/.gtkrc-2.0.bak
4. Launch Plasma's GTK config.:
> kcmshell5 kde-gtk-config

OBSERVED RESULT
kde-gtk-config still tries to read from ~/.gtkrc-2.0 instead of ~/.gtkrc-2.0.bak.

EXPECTED RESULT
kde-gtk-config should respect the GTK2_RC_FILES variable when reading/writing to the GTK2 config file.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux
KDE Plasma Version: 5.17.4
KDE Frameworks Version: 5.65.0
Qt Version: 5.14.0
Comment 1 Mikhail Zolotukhin 2020-01-02 20:30:09 UTC
Git commit 5734413d8105699252a3a0cfbba2265169581909 by Mikhail Zolotukhin.
Committed on 02/01/2020 at 20:29.
Pushed by gikari into branch 'master'.

Respect GTK2_RC_FILES environmental variable

Summary:
If the above variable is set and it does not contain multiple paths,
write GTK2 config into the designated config file, instead of the
default one.
FIXED-IN: 5.18.0

Test Plan:
Check if the custom file provided by env variable is modified, when changing any settings, that are synchronized by kded module (icon theme, cursor theme etc)
Simple test:

# `mv ~/.gtkrc-2.0 ~/.gtkrc-2.0.bak`
# `export GTK2_RC_FILES=~/.gtkrc-2.0.bak`
# Restart kded5 with the above env variable
# Change e.g. icon theme and see, that `.gtkrc-2.0.bak` is modified, but `.gtkrc-2.0`

Reviewers: ngraham

Reviewed By: ngraham

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26375

M  +4    -1    kded/configeditor.cpp

https://commits.kde.org/kde-gtk-config/5734413d8105699252a3a0cfbba2265169581909
Comment 2 Guilherme Silva 2020-01-02 20:37:36 UTC
That was fast! Thanks a bunch, guys! 🎉
Comment 3 Mikhail Zolotukhin 2020-02-05 18:34:25 UTC
*** Bug 417090 has been marked as a duplicate of this bug. ***
Comment 4 daiaji 2022-11-30 16:16:38 UTC
Even if I declare the GTK2_RC_FILES variable, ~/.gtkrc-2.0 is still created, I don't know what's going on.
Comment 5 daiaji 2022-11-30 17:23:21 UTC
```
2022-12-01 01:16:18,148 INFO [default] Configuration file : /home/test/loggedfs.xml
2022-12-01 01:16:18,148 INFO [default] LoggedFS starting at /home/test.
2022-12-01 01:16:18,148 INFO [default] Using configuration file /home/test/loggedfs.xml.
2022-12-01 01:16:18,149 INFO [default] chdir to /home/test
2022-12-01 01:16:27,108 INFO [default] mknod /home/test/.gtkrc-2.0 100644 S_IFREG (normal file creation) {SUCCESS} [ pid = 4916 /usr/bin/kded5 uid = 1000 ]
2022-12-01 01:16:27,108 INFO [default] open readwrite /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 4916 /usr/bin/kded5 uid = 1000 ]
2022-12-01 01:16:27,108 INFO [default] release /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 0 (null) uid = 0 ]
2022-12-01 01:16:27,108 INFO [default] unlink /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 4916 /usr/bin/kded5 uid = 1000 ]
2022-12-01 01:16:27,108 INFO [default] mknod /home/test/.gtkrc-2.0 100644 S_IFREG (normal file creation) {SUCCESS} [ pid = 4916 /usr/bin/kded5 uid = 1000 ]
2022-12-01 01:16:27,109 INFO [default] open writeonly /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 4916 /usr/bin/kded5 uid = 1000 ]
2022-12-01 01:16:27,109 INFO [default] release /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 0 (null) uid = 0 ]
2022-12-01 01:16:27,405 INFO [default] open readwrite /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 5116 /usr/bin/gmenudbusmenuproxy uid = 1000 ]
2022-12-01 01:16:27,405 INFO [default] truncate /home/test/.gtkrc-2.0 to 0 bytes {SUCCESS} [ pid = 5116 /usr/bin/gmenudbusmenuproxy uid = 1000 ]
2022-12-01 01:16:27,405 INFO [default] release /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 0 (null) uid = 0 ]
2022-12-01 01:16:27,409 INFO [default] statfs /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 5116 /usr/bin/gmenudbusmenuproxy uid = 1000 ]
2022-12-01 01:16:32,388 INFO [default] open /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 5637 /usr/bin/dolphin uid = 1000 ]
2022-12-01 01:16:32,388 INFO [default] release /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 0 (null) uid = 0 ]
2022-12-01 01:16:32,396 INFO [default] statfs /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 5637 /usr/bin/dolphin uid = 1000 ]
2022-12-01 01:17:01,049 INFO [default] open readwrite /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 5116 /usr/bin/gmenudbusmenuproxy uid = 1000 ]
2022-12-01 01:17:01,049 INFO [default] truncate /home/test/.gtkrc-2.0 to 0 bytes {SUCCESS} [ pid = 5116 /usr/bin/gmenudbusmenuproxy uid = 1000 ]
2022-12-01 01:17:01,049 INFO [default] release /home/test/.gtkrc-2.0 {SUCCESS} [ pid = 0 (null) uid = 0 ]
2022-12-01 01:17:01,542 INFO [default] LoggedFS closing.
```
```
cat /etc/security/pam_env.conf

XDG_CONFIG_HOME DEFAULT=@{HOME}/.config
XDG_CACHE_HOME DEFAULT=@{HOME}/.cache
XDG_DATA_HOME DEFAULT=@{HOME}/.local/share
XDG_STATE_HOME DEFAULT=@{HOME}/.local/state

GTK2_RC_FILES DEFAULT=${XDG_CONFIG_HOME}/gtk-2.0/gtkrc
```
Return of the bug?
Comment 6 Andrei 2023-02-10 01:32:33 UTC
Same issue:
Operating System: Kubuntu 22.10
KDE Plasma Version: 5.25.5
KDE Frameworks Version: 5.98.0
Qt Version: 5.15.6
Comment 7 Nate Graham 2023-02-11 02:34:53 UTC
This was fixed ages ago with no other reports since then. I suspect the issue you're facing is either something else or at least has a different root cause. Please file a new (detailed) bug report for it. In general it's best to file a new report rather than re-opening an old one. Thanks!
Comment 8 Rocket Aaron 2023-02-19 09:30:38 UTC
I can reproduce it too, on Plasma 5.27.0. After some experiment, I think I've figured out what's happening.

gmenu-dbusmenu-proxy hardcoded gtkrcPath as `QDir::homePath() + QLatin1String("/.gtkrc-2.0")`, but it's not creating the file if it's not present. kde-gtk-config's `Gtk2ConfigEditor::removeLegacyStrings()` is the cause:
https://github.com/KDE/kde-gtk-config/blob/4a9185dbc67543544f7010cf39e6c87af44aeca8/kded/config_editor/gtk2.cpp#L54
it uses `Utils::readFileContents(QFile &file)`
https://github.com/KDE/kde-gtk-config/blob/4a9185dbc67543544f7010cf39e6c87af44aeca8/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://github.com/KDE/plasma-workspace/blob/89d1f0e07955427a083cbc5af34e0ae9fdcdaad4/gmenu-dbusmenu-proxy/menuproxy.cpp#L106
and write the content to the file.

If gmenu-dbusmenu-proxy is disabled, it would simply results an empty `~/.gtkrc-2.0` file, as this bug describes:
https://bugs.kde.org/show_bug.cgi?id=417534
Comment 9 Fushan Wen 2023-02-25 14:48:47 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 417534
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 10 Fushan Wen 2023-02-25 14:51:00 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 417534
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