Commit 3165c9b
committed
fix: defer DSysInfo queries in plugins to avoid dlopen deadlock
The control center loads plugins via QPluginLoader during startup. Several
plugins called DSysInfo::uosType()/uosEditionType()/deepinType()/isDeepin()
in global/static initialization (namespace-scope const variables), which runs
while the dynamic loader holds the glibc/ld.so loader lock.
On systems where /etc/os-version is missing or malformed, DSysInfo internally
emits qWarning(), which enters the dtklog appender pipeline. Meanwhile another
thread already holding the dtklog write lock formats %{function} via
QRegularExpression/pcre2, which can trigger TLS/loader initialization and
wait on the same loader lock. This forms a classic deadlock:
Thread A: loader lock -> DSysInfo -> qWarning -> wait dtklog lock
Thread B: dtklog lock -> %{function} regex/pcre2/TLS -> wait loader lock
Replace the namespace-scope const globals (UosType, IsServerSystem,
IsCommunitySystem, etc.) with static inline lazy-init helper functions that
compute the value once on first runtime call via function-local statics.
This keeps the "compute once" semantics but moves the DSysInfo calls out of
the dlopen global constructor phase, breaking the loader-lock side of the
deadlock chain.
Affected plugins: sound, power, commoninfo, deepinid.
The helpers use `static inline` to preserve internal linkage (matching the
original const globals) and avoid ODR/symbol collisions across plugins that
share the same utils.h include guard name.
Log: defer DSysInfo queries in plugins to avoid dlopen deadlock
fix: 延迟插件中 DSysInfo 的调用以避免 dlopen 死锁
控制中心启动时通过 QPluginLoader 加载插件。多个插件在全局/静态初始化
(命名空间作用域 const 变量)中调用了 DSysInfo::uosType() 等接口,这些
代码在动态加载器持有 glibc/ld.so 加载锁期间执行。
当 /etc/os-version 缺失或格式异常时,DSysInfo 内部会触发 qWarning(),
进入 dtklog appender 写入流程。此时另一个线程已持有 dtklog 写锁,正在
格式化 %{function},经由 QRegularExpression/pcre2 触发 TLS/加载器初始化,
并等待同一把加载锁,形成经典死锁:
线程 A:加载锁 -> DSysInfo -> qWarning -> 等待 dtklog 锁
线程 B:dtklog 锁 -> %{function} regex/pcre2/TLS -> 等待加载锁
将命名空间作用域的 const 全局变量(UosType、IsServerSystem 等)替换为
static inline 懒加载辅助函数,通过函数局部 static 在首次运行时调用时
计算一次。保留"只计算一次"语义,但把 DSysInfo 调用移出 dlopen 全局构造
阶段,打断死锁链中加载锁一侧。
涉及插件:sound、power、commoninfo、deepinid。
辅助函数使用 static inline 保持内部链接(与原 const 全局变量一致),
避免多个共用 utils.h include guard 名的插件之间产生 ODR/符号冲突。
Log: 延迟插件中 DSysInfo 的调用以避免 dlopen 死锁
Change-Id: I1b72cc0a72252730e640997b5481c96f3989343e1 parent 1bcefde commit 3165c9b
8 files changed
Lines changed: 98 additions & 40 deletions
File tree
- src
- plugin-commoninfo/operation
- plugin-deepinid/operation
- plugin-power/operation
- plugin-sound/operation
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
43 | 75 | | |
44 | 76 | | |
45 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
410 | | - | |
| 410 | + | |
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
| |||
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
425 | | - | |
| 425 | + | |
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
| 199 | + | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | | - | |
| 204 | + | |
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
41 | 63 | | |
42 | 64 | | |
43 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
334 | | - | |
| 334 | + | |
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| |||
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
344 | | - | |
| 344 | + | |
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
100 | | - | |
| 103 | + | |
101 | 104 | | |
102 | 105 | | |
103 | 106 | | |
| |||
733 | 736 | | |
734 | 737 | | |
735 | 738 | | |
736 | | - | |
| |||
0 commit comments