fix: strip input suffix from m_SysPath on mismatch - #736
Conversation
1. Root cause: getPS2Syspath() only updates m_SysPath on event-number match success; on failure m_SysPath keeps the hwinfo raw SysFS ID with /input/inputN or /inputN suffix 2. Fix: strip the trailing input suffix from m_SysPath after matching so wakeupPath() and DBus wakeup call use the correct sysfs path 3. Impact: external keyboard changes input enumeration and triggers the mismatch; "allow waking up computer" menu is no longer greyed out for PS/2 and L2C keyboards Log: Fix greyed-out wake-up menu item after attaching external keyboard Influence: 1. Connect an external keyboard and verify the right-click "allow waking up computer" menu is enabled for PS/2 keyboard 2. Repeat the same check for L2C (i2c_designware) keyboard 3. Verify wake-up-from-keyboard still works without external keyboard fix: 修复外接键盘后唤出电脑菜单置灰 1. 根因:getPS2Syspath() 仅在 event 号匹配成功时更新 m_SysPath;匹配失败时 m_SysPath 仍保留 hwinfo 原始 SysFS ID(含 /input/inputN 或 /inputN 后缀) 2. 方案:匹配后剥离 m_SysPath 尾部的 /input/inputN (i2c_designware)或 /inputN 后缀,使 wakeupPath() 与 DBus 唤出调用拼出正确的 sysfs 路径 3. 影响:外接键盘改变输入设备枚举导致匹配失败,修复后 PS/2 与 L2C 键盘右键"允许唤出电脑"菜单不再置灰 Log: 修复外接键盘后"允许唤出电脑"菜单置灰问题 Influence: 1. 外接键盘后验证 PS/2 键盘右键"允许唤出电脑"菜单可用 2. 外接键盘后验证 L2C(i2c_designware)键盘同样可用 3. 不外接键盘时验证唤出电脑功能无回归 PMS: BUG-294489
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tianming-1996 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 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideNormalizes keyboard sysfs paths in getPS2Syspath() by stripping trailing /input segments when the /proc/bus/input/devices event match fails, ensuring wakeup-related code receives a valid path. Sequence diagram for normalized sysfs path in keyboard wakeup flowsequenceDiagram
actor User
participant DeviceManagerUI
participant DeviceInput
participant ProcBusInputDevices
participant DBusWakeupInterface
User->>DeviceManagerUI: open context_menu "允许唤出电脑"
DeviceManagerUI->>DeviceInput: setInfoFromHwinfo(hwinfoOutput)
DeviceInput->>ProcBusInputDevices: getPS2Syspath(dfs)
ProcBusInputDevices-->>DeviceInput: event_match_or_mismatch
alt event_match_success
DeviceInput->>DeviceInput: assign m_SysPath from regfs_cap
else event_match_failure
DeviceInput->>DeviceInput: remove(QRegExp("/input/input[0-9]{1,2}$"))
DeviceInput->>DeviceInput: remove(QRegExp("/input[0-9]{1,2}$"))
end
DeviceManagerUI->>DeviceInput: wakeupPath()
DeviceInput-->>DeviceManagerUI: /sys/.../power/wakeup (from normalized m_SysPath)
DeviceManagerUI->>DeviceInput: canWakeupMachine()
DeviceInput-->>DeviceManagerUI: true
DeviceManagerUI->>DBusWakeupInterface: setWakeupMachine(sysPath())
DBusWakeupInterface-->>DeviceManagerUI: success
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 left some high level feedback:
- The
i2c_designwarecheck makes the suffix stripping logic device-name–dependent; consider using a single regex that handles both/input/inputNand/inputNsuffixes without relying on the driver string. - New usage of
QRegExpcould be modernized toQRegularExpressionfor consistency with newer Qt APIs and better performance, especially since this path normalization may run multiple times.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `i2c_designware` check makes the suffix stripping logic device-name–dependent; consider using a single regex that handles both `/input/inputN` and `/inputN` suffixes without relying on the driver string.
- New usage of `QRegExp` could be modernized to `QRegularExpression` for consistency with newer Qt APIs and better performance, especially since this path normalization may run multiple times.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 匹配失败时 m_SysPath 仍保留 hwinfo 原始 SysFS ID(含 /input/inputN 或 /inputN 后缀),
// 需剥离后缀得到正确设备 syspath,否则 wakeupPath() 等会拼出错误路径
static const QRegularExpression i2cPattern("/input/input[0-9]{1,2}$");
static const QRegularExpression normalPattern("/input[0-9]{1,2}$");
if (m_SysPath.contains("i2c_designware")) {
m_SysPath.remove(i2cPattern);
} else {
m_SysPath.remove(normalPattern);
}
return true;
} |
Root Cause Analysis
In
DeviceInput::getPS2Syspath()(DeviceInput.cpp:200-240),m_SysPathis only reassigned when the event-number match against/proc/bus/input/devicessucceeds. When the match fails,m_SysPathretains the raw hwinfo "SysFS ID" value, which carries an extra/input/inputN(i2c_designware) or/inputNsuffix. DownstreamwakeupPath()then builds/sys/.../input/power/wakeup(an extrainputlayer) which does not exist, socanWakeupMachine()returns false and the right-click menu item "允许唤出电脑" (Allow waking up computer) is greyed out. Connecting an external keyboard shifts input device enumeration, causing the event-number mismatch betweenhwinfo --keyboardand/proc/bus/input/devices. PS/2 and L2C keyboards share the samesetInfoFromHwinfo→getPS2Syspathpath, which is why both are affected.Fix Approach
Add an idempotent fallback at the end of
getPS2Syspath()(beforereturn true) that strips the trailing/input/inputN(for i2c_designware) or/inputNsuffix fromm_SysPath. Normalizing at the source fixes both the client-sidewakeupPath()check and the server-sideDBusWakeupInterface::setWakeupMachine()call that receivessysPath(), matching the analysis report's Method A recommendation.Change Safety Assessment
Code Safety
m_SysPath = regfs.cap(1)assignment (line 236) has been untouched since its introduction (commitbe1e8349, 2022-03-08); this change does not revert any historical fix — related bugs (172035, 147047, 147393) target different code paths (USB mouse DBus, serial ID logic).wakeupPath()(DeviceInput.cpp:408) andsetWakeupMachine()(PageSingleInfo.cpp:351,TextBrowser.cpp:114) — both are positively fixed by the normalized path. The strip is idempotent (no-op when the suffix is already absent on a successful match).Business Impact Scope
Device Manager — keyboard/mouse "Allow waking up computer": the right-click context menu for PS/2 and L2C keyboards. After attaching an external keyboard the menu item must appear enabled and toggle correctly; the server-side wake-up DBus call must receive a valid sysfs path.
Verification Suggestion
Test with and without an external keyboard: confirm the "允许唤出电脑" menu item is enabled for both PS/2 and L2C (i2c_designware) keyboards, and that wake-from-keyboard still functions as a regression check.
根因分析
DeviceInput::getPS2Syspath()(DeviceInput.cpp:200-240)仅在 event 号与/proc/bus/input/devices匹配成功时才重新赋值m_SysPath;匹配失败时m_SysPath仍保留 hwinfo 原始 "SysFS ID" 值,带有多余的/input/inputN(i2c_designware)或/inputN后缀。下游wakeupPath()据此拼出/sys/.../input/power/wakeup(多一层input),该文件不存在,canWakeupMachine()返回 false,右键菜单项"允许唤出电脑"被置灰。外接键盘改变输入设备枚举,导致hwinfo --keyboard与/proc/bus/input/devices的 event 号不一致而匹配失败。PS/2 与 L2C 键盘走同一setInfoFromHwinfo→getPS2Syspath路径,故两者同时受影响。修复方案
在
getPS2Syspath()末尾(return true之前)新增幂等的兜底逻辑,剥离m_SysPath尾部的/input/inputN(i2c_designware)或/inputN后缀。在源头规范化m_SysPath,一次性修复客户端wakeupPath()检查与服务端DBusWakeupInterface::setWakeupMachine()调用两条路径,与分析报告 Method A 建议一致。改动安全评估
代码安全评估
m_SysPath = regfs.cap(1)(第 236 行)自引入以来(commitbe1e8349,2022-03-08)未被修改,本次修复不撤销任何历史修复——关联 bug(172035、147047、147393)走的是 USB 鼠标 DBus、序列号获取等不同路径。wakeupPath()(DeviceInput.cpp:408)与setWakeupMachine()(PageSingleInfo.cpp:351、TextBrowser.cpp:114)均被正面修复;剥离幂等,匹配成功时后缀已不存在,remove 为空操作。业务影响范围
设备管理器 — 键鼠"允许唤出电脑"功能:PS/2 与 L2C 键盘右键上下文菜单。外接键盘后菜单项应正常显示并可切换,服务端唤出 DBus 调用应收到正确 sysfs 路径。
验证建议
分别在不外接与外接键盘环境下测试:确认 PS/2 与 L2C(i2c_designware)键盘"允许唤出电脑"菜单项可用,并回归验证键盘唤出功能正常。
PMS: BUG-294489
Summary by Sourcery
Bug Fixes: