feat(control): expose VT management over DDE control socket#3
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zccrs 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 |
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
a8bd4a5 to
e9fcf19
Compare
There was a problem hiding this comment.
Pull request overview
EN: This PR extends dde-seatd’s control socket protocol to expose basic VT management (query active VT, query a free VT, and request a VT switch), reusing the seat VT state machine so VT switching can be routed through dde-seatd instead of direct ioctls in downstream components (e.g. ddm).
中文: 该 PR 扩展了 dde-seatd 的 control socket 协议,新增 VT 管理能力(查询当前活动 VT、查询空闲 VT、请求切换 VT),并复用现有 seat 的 VT 状态机,从而让下游组件(如 ddm)可以通过 dde-seatd 统一进行 VT 控制而不是直接 ioctl。
Changes / 变更:
- Add seat-level APIs for active VT query, free VT query, and VT switch request. / 新增 seat 层接口:获取活动 VT、查找空闲 VT、请求切换 VT。
- Extend control socket opcodes and implement request handlers + responses (
CONTROL_OK, VT state events). / 扩展控制协议 opcode,并实现请求处理与响应(CONTROL_OK、VT 状态事件)。 - Update public headers for the new APIs and protocol structs. / 更新公共头文件以暴露新接口与协议结构体。
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
seatd/seat.c |
Adds VT query/switch entry points in the seat layer. |
seatd/control.c |
Implements new control-socket operations and response helpers for VT management. |
include/seat.h |
Exposes new seat VT APIs in the public header. |
include/control.h |
Adds new control protocol opcodes and request/response structs. |
e9fcf19 to
b76bafb
Compare
b76bafb to
2d6f203
Compare
|
Addressed the valuable review findings in this branch:
I also checked the other Copilot point about Local validation: |
Add active-vt, free-vt, and switch-vt control operations so DDM can stop issuing VT ioctls directly. 添加 active-vt、free-vt 和 switch-vt control 操作,使DDM不再直接发起VT ioctl。 Reuse the existing seat VT state machine for grouped and unmanaged switches. 复用现有 seat VT 状态机处理 grouped 与非托管切换。 Log: 为control socket补齐VT管理能力 Influence: DDM可通过dde-seatd统一查询和切换VT,减少双写状态机。
2d6f203 to
2855aa0
Compare
|
@copilot review |
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff。本次修改主要为seatd添加了获取活动VT、查找空闲VT以及切换VT的控制接口,并对VT状态更新的错误处理进行了增强。 整体来看,代码结构清晰,对系统调用的错误处理(如保存 1. 语法与逻辑问题
2. 代码质量与可读性
3. 代码性能
4. 代码安全
改进后的代码示例针对上述意见,以下是修改后的关键代码片段: seat.c 改进: static int seat_update_vt(struct seat *seat) {
int tty0fd = terminal_open(0);
if (tty0fd == -1) {
log_errorf("Could not open tty0 to update VT: %s", strerror(errno));
return -1;
}
// 建议:调用前清空errno,防止残留值干扰成功返回时的判断
errno = 0;
int vt = terminal_current_vt(tty0fd);
int saved_errno = errno; // 如果terminal_current_vt出错,这里捕获
close(tty0fd);
if (vt <= 0) {
// 如果vt<=0且errno未被设置,则默认返回ENOENT
errno = saved_errno != 0 ? saved_errno : ENOENT;
return -1;
}
seat->cur_vt = vt;
return 0;
}
int seat_find_available_vt(struct seat *seat) {
if (!seat->vt_bound) {
errno = EINVAL;
return -1;
}
int tty0fd = terminal_open(0);
if (tty0fd == -1) {
return -1;
}
int vt = terminal_find_available(tty0fd);
close(tty0fd); // 直接关闭,如果vt==-1,errno不受close影响
// 移除了冗余的saved_errno逻辑
return vt;
}
// 增加 VT 合法范围限制
#define MAX_VT_NUMBER 63 // 根据实际系统内核配置调整
int seat_switch_vt(struct seat *seat, int vt) {
if (!seat->vt_bound) {
errno = EINVAL;
return -1;
}
// 增加 vt 上界检查,防止恶意输入
if (vt <= 0 || vt > MAX_VT_NUMBER) {
errno = EINVAL;
return -1;
}
// 保留当前VT检查逻辑,但需注意非原子性
if (seat_update_vt(seat) == -1) {
return -1;
}
if (seat->cur_vt == vt) {
return 0;
}
if (seat->pending_vt_switch > 0) {
errno = EBUSY;
return -1;
}
seat->pending_vt_switch = vt;
if (vt_switch(seat, vt) == -1) {
seat->pending_vt_switch = 0;
return -1;
}
return 0;
}control.c 改进: #define DEFAULT_SEAT_NAME "seat0"
static int handle_get_active_vt(struct control_client *client) {
// 使用宏替代硬编码
struct seat *seat = server_get_seat(client->server, DEFAULT_SEAT_NAME);
if (seat == NULL) {
return control_send_error(client, ENOENT);
}
int vt = seat_get_active_vt(seat);
if (vt == -1) {
return control_send_error(client, errno);
}
return control_send_vt_state(client, CONTROL_ACTIVE_VT, vt);
}
// handle_find_free_vt 和 handle_switch_vt 同样替换 "seat0" 为 DEFAULT_SEAT_NAME希望这些审查意见和代码改进能对你有所帮助!如果有任何疑问,欢迎随时提问。 |
Summary
Test