Commit 02784b0
authored
Fix race in dark mode detection (#13366)
The current dark mode detection implementation is prone to a race
between an asynchronous D-Bus method call in NixUtils::NixUtils() and
bootstrap logic in Bootstrap::bootstrap(). This race condition causes
dark mode detection to fail intermittently during application startup.
The sequence of events in the failing case is as follows:
1. In the Application constructor, osUtils is instantiated, causing
the NixUtils constructor to run.
2. An asynchronous D-Bus method call is issued to query the value of
the org.freedesktop.appearance.color-scheme key.
3. Bootstrap code runs. In particular, a prctl() system call is
issued to set the keepassxc process "dumpable" attribute to 0.
4. xdg-desktop-portal begins handling the D-Bus method call initiated
in step 2. Flatpak detection logic is invoked, triggering an
attempt to access /proc/<pid>/root, where <pid> is the PID of the
keepassxc process.
5. Since the keepassxc process had its "dumpable" attribute set to 0
in step 3, its /proc/<pid>/root entry becomes owned by root. This
causes the access attempt from xdg-desktop-portal to fail, which in
turn causes the D-Bus method call to fail as well. As a result, the
registered callback (NixUtils::handleColorSchemeRead()) is never
invoked, effectively breaking dark mode detection.
If xdg-desktop-portal completes its permission checks before the
prctl() system call is issued (that is, if the order of steps 3 and 4
is reversed), everything works correctly.
Fix by replacing the asynchronous D-Bus method call with a synchronous
one, preventing bootstrap code from executing while the D-Bus call is
still pending.
* Use ReadOne D-Bus method instead of Read
The org.freedesktop.portal.Settings.Read method is deprecated. Replace
its use with org.freedesktop.portal.Settings.ReadOne and adjust reply
handling accordingly.
Remove NixUtils::handleColorSchemeRead(), which is no longer needed.1 parent 36fbca4 commit 02784b0
2 files changed
Lines changed: 7 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| |||
359 | 362 | | |
360 | 363 | | |
361 | 364 | | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | 365 | | |
369 | 366 | | |
370 | 367 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
| |||
0 commit comments