feat(server): add D-Bus service and event relay dispatcher - #257
Conversation
|
Warning
详情 {
"export": {
"src/server/dbus-service.h": {
"b": [
" * An opaque D-Bus service object that exports the org.deepin.Anything"
]
}
}
} |
Reviewer's GuideThe server now acquires org.deepin.Anything on the system D-Bus and exposes authorized event channels backed by a worker-thread relay that broadcasts raw fs_event structs, while listeners adopt explicit thread-local GMainContexts and tests cover the new relay behavior. Sequence diagram for D-Bus event channel acquisition and relaysequenceDiagram
participant Client
participant DBus as org.deepin.Anything
participant Relay as ServerEventRelayDispatcher
participant Worker as Relay worker thread
participant Channels as Event relay channels
Client->>DBus: SetAllowCaller(unique_name)
DBus-->>Client: Return success
Client->>DBus: GetEventChannel()
DBus->>Relay: server_event_relay_dispatcher_get_event_channel()
Relay->>Worker: Queue request and wake worker
Worker->>Channels: event_relay_dispatcher_get_event_channel()
Channels-->>Worker: fd
Worker-->>DBus: get_event_channel_callback(fd, event_protocol_id)
DBUS-->>Client: Return Unix fd and protocol id
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/server/dbus-service.c" line_range="144-145" />
<code_context>
+ gpointer key;
+ g_hash_table_iter_init(&ht_iter, service->allow_callers);
+ while (g_hash_table_iter_next(&ht_iter, &key, NULL)) {
+ if (!g_hash_table_contains(live_names, key)) {
+ g_hash_table_iter_remove(&ht_iter);
+ g_message("allow_callers: evicted stale entry %s", (gchar *)key);
+ }
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** g_hash_table_iter_remove frees the current allow-list key, then the callback logs that freed key through `key`, causing a use-after-free during stale-caller cleanup.
**Triggers:** When ListNames contains a caller that is no longer present in `allow_callers`.
**Suggested fix:** Copy the key for logging before removal, or log it before calling `g_hash_table_iter_remove`.
```suggestion
g_message("allow_callers: evicted stale entry %s", (gchar *)key);
g_hash_table_iter_remove(&ht_iter);
```
</issue_to_address>
### Comment 2
<location path="src/server/dbus-service.c" line_range="94-95" />
<code_context>
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, /* timeout — use default */
+ NULL, /* cancellable */
+ list_names_callback,
+ service); /* user_data — borrowed service */
+ }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** The asynchronous ListNames call stores a raw `AnythingDBusService *` as user data, but service destruction does not cancel or otherwise synchronize with that call; its callback dereferences the freed service through `service->allow_callers`.
**Triggers:** When the server shuts down while a SetAllowCaller-triggered ListNames request is still pending.
**Suggested fix:** Hold a reference to the service until the async callback completes, or cancel pending calls before freeing the service.
</issue_to_address>Replace socket-based event dispatcher with a D-Bus service exporting org.deepin.Anything interface and a relay dispatcher that broadcasts raw fs_event structs to connected channels via a worker thread. 新增D-Bus服务接口org.deepin.Anything,提供SetAllowCaller和 GetEventChannel方法;新增事件中继分发器通过worker线程广播 原始fs_event;修复监听器GSource附加到错误GMainContext的问题; fs_event结构src/dst合并为path字段,minor类型扩展为guint32。 Log: 新增D-Bus服务及事件中继分发器,替换旧的socket分发方式 PMS: BUG-370779 Influence: server服务改为D-Bus方式提供事件通道,影响事件监听和分发的整体流程
167b4ea to
c32af1a
Compare
|
Warning
详情 {
"export": {
"src/server/dbus-service.h": {
"b": [
" * An opaque D-Bus service object that exports the org.deepin.Anything"
]
}
}
} |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 代码结构完整,D-Bus服务、事件中继分发器、监听器GSource修复均实现正确。线程同步机制(GAsyncQueue + mutex/cond)实现正确,内存管理遵循GLib规范。GSource修复正确:从g_io_add_watch(附加到全局默认上下文)改为g_source_attach到线程局部上下文。 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: GSource创建模式可抽取为公共辅助函数以减少重复代码。注释非常完善,包括设计决策、内存所有权、线程安全说明。函数长度合理,模块划分清晰。 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 事件入队使用GAsyncQueue(O(1)),设计合理。max_event_channel=30限制并发通道数,防止资源耗尽。allow_callers懒清理使用异步ListNames调用,不阻塞主线程。g_slice分配器本身效率很高,当前开销在可接受范围内。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: D-Bus安全配置合理:root可own,deepin-daemon组可调用,默认拒绝SetAllowCaller。GetEventChannel有应用层allow_callers检查作为深度防御。缓冲区操作有边界检查(safe_string_copy, g_strlcpy)。文件描述符管理正确(FDList dup后关闭原始fd)。线程安全:GAsyncQueue线程安全,allow_callers仅主线程访问(有文档说明)。日志不泄露敏感信息。 💡 改进建议代码示例// 可选:抽取GSource创建为公共辅助函数
static guint
attach_io_source_to_context(GIOChannel *channel,
GIOCondition condition,
GSourceFunc callback,
gpointer data,
GMainContext *ctx)
{
GSource *source = g_io_create_watch(channel, condition);
if (source == NULL)
return 0;
g_source_set_callback(source, callback, data, NULL);
guint id = g_source_attach(source, ctx);
g_source_unref(source);
return id;
}本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, wangrong1069 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
684c18a
into
linuxdeepin:develop/eagle
Replace socket-based event dispatcher with a D-Bus service exporting org.deepin.Anything interface and a relay dispatcher that broadcasts raw fs_event structs to connected channels via a worker thread.
新增D-Bus服务接口org.deepin.Anything,提供SetAllowCaller和
GetEventChannel方法;新增事件中继分发器通过worker线程广播
原始fs_event;修复监听器GSource附加到错误GMainContext的问题;
fs_event结构src/dst合并为path字段,minor类型扩展为guint32。
Log: 新增D-Bus服务及事件中继分发器,替换旧的socket分发方式
PMS: BUG-370779
Influence: server服务改为D-Bus方式提供事件通道,影响事件监听和分发的整体流程
Summary by Sourcery
Replace the server's socket event-dispatcher interface with an authorized D-Bus service and worker-backed raw event relay.
New Features:
Bug Fixes:
Enhancements:
Build:
Deployment:
Tests: