Repository navigation
fix(lock): KDE 解锁后清理残留的锁屏界面进程,避免再次锁屏变成透明锁屏 - #251
Conversation
- 现象:KDE X11 上远程用密码解锁后马上再锁屏,输入被抓住但桌面内容可见, ksmserver 日志为 "QProcess::start: Process is already running" - 原因(对照 kscreenlocker v6.3.5):密码通过后 greeter 打印 "Unlocked" 并退出事件循环, ~PamAuthenticator 等指纹 PAM 线程,而 pam_fprintd.so timeout=-1 只有读到手指才返回; 远程用户按不到指纹,进程一直留着,下一次锁屏起不了新的 greeter, 旧进程以 0 退出时 ksld 还会把它当成解锁 - 处理:会话由锁定变为未锁定时记下本用户的 kscreenlocker_greet(pid + 启动时间), 3 秒后仍是同一进程就 SIGKILL。greeter 的 SIGTERM 处理在已退出的事件循环里,不起作用; 未锁定时 ksld 忽略这次退出,已再次锁屏时 ksld 按 greeter 崩溃重启一个正常的锁屏界面 - 验证:Debian 13 / Plasma 6.3 X11(ThinkPad T14s,带指纹)上远程解锁后再锁屏恢复正常 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
感谢详细的根因分析。已审阅 diff:仅在 锁定→解锁 时扫描本用户 已请 Codex 审查。@codex review 🤖 Generated with Claude Code |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7160a892f7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if entry.metadata().ok()?.uid() != uid { return None; } | ||
| Some((pid, start_time(pid)?)) |
There was a problem hiding this comment.
Scope greeter cleanup to the unlocked graphical session
If the same UID has two graphical sessions and the other session remains locked, unlocking the session monitored by logind::locked() (User.Display) also selects the other session's greeter here, since only UID and process name are checked. That healthy greeter can retain the same start time beyond the three-second grace period and therefore receive SIGKILL, terminating its authentication UI even though its session never unlocked. Filter candidates by the unlocked logind session/display rather than treating every same-user greeter as stale.
AGENTS.md reference: AGENTS.md:L272-L274
Useful? React with 👍 / 👎.
|
Codex 的 P2(stale_greeter.rs:44)核实成立:候选只按 UID + 进程名筛选,同一用户若有两个图形会话、另一个仍处于锁定,解锁被监视的会话时会把另一个会话里正常的 greeter 一并 SIGKILL。建议把候选限定到刚解锁的那个 logind 会话,例如比对 🤖 Generated with Claude Code |
候选原先只按 UID + 进程名筛选:同一用户有两个图形会话、另一个仍锁定时, 解锁被监视的会话会把另一个会话里正常的 greeter 一并杀掉(Codex P2)。 现在只选属于 User.Display 会话的 greeter:先看 cgroup 的 session-<id>.scope,没有时看进程环境里的 XDG_SESSION_ID;会话判断不出来就不动。 没有用 /proc/<pid>/sessionid:systemd 托管的 Plasma(实测 6.3)里 ksmserver 和 greeter 跑在 user@<uid>.service 下,cgroup 是 plasma-ksmserver.service, sessionid 是用户管理器自己的会话(实测 4),而图形会话是 3,两者对不上。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
已按建议把候选限定到刚解锁的 logind 会话(cbe7ed1),并补了测试;会话判断不出来时不杀。 有一点和建议不同:没有用 |
|
cbe7ed1 看过:候选限定为刚解锁的 logind 会话(cgroup @codex review 🤖 Generated with Claude Code |
上一个提交实机无效:kscreenlocker_greet 启动时 prctl(PR_SET_DUMPABLE, 0), /proc/<pid>/environ 读不到,会话判断为未知,残留 greeter 没被清理, 透明锁屏复现(ksmserver 再次报 QProcess::start: Process is already running)。 greeter 自己判断不出会话时,改看启动它的父进程(ksmserver / kwin_wayland 里的 ksld,ppid 取自 /proc/<pid>/stat 第 4 字段),它与 greeter 同属一个会话且可读。 父进程也判断不出来时仍然不动。 验证:三个改名为 kscreenlocker_g 的不可读进程,父进程分别在会话 3、会话 7、 无 XDG_SESSION_ID;监视会话 3 时只有第一个被清理。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
补充:cbe7ed1 实机无效。kscreenlocker_greet 启动时 |
|
2c83c93 看过:greeter 设了不可 dump 读不到 environ 时,回退看父进程(ksmserver/kwin)所属会话,仍判断不出就不动,并有 Plasma 6.3 X11 实机验证,合理。CI 失败是 Ubuntu 软件源超时,已重跑。 @codex review 🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c83c93737
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let spawned = std::thread::Builder::new().name("uu-greeter-reap".into()).spawn(|| { | ||
| let Some(session) = super::display_session() else { return }; | ||
| let seen = greeters(&session); |
There was a problem hiding this comment.
Tie greeter candidates to the observed unlock
If the same session is locked again before this background display_session() query and /proc scan finish, seen can contain the healthy greeter created for the new lock, even when the previous greeter exited normally. That new process survives the grace period because authentication is still pending, then receives SIGKILL, unnecessarily interrupting the authentication UI. A controlled probe with a same-session, non-dumpable test greeter started after reap_after_unlock() but before discovery completed reproduced this kill. Record candidates, or an eligibility start-time cutoff, at the unlock notification so greeters created for subsequent locks cannot be selected.
AGENTS.md reference: AGENTS.md:L274-L275
Useful? React with 👍 / 👎.
|
2c83c93 的父进程回退和实机验证都看过了。Codex 新的 P2 核实成立:候选是在后台 🤖 Generated with Claude Code |
候选是在后台线程查完会话、扫完 /proc 之后才收集的。这段时间里同一会话若又被 锁上,新锁屏对应的正常 greeter 也会进入候选,3 秒后仍在认证就被杀掉(Codex P2)。 收到解锁通知时在调用线程上记下时刻(CLOCK_BOOTTIME,换算成 stat 第 22 字段的 时钟计数),只把启动时间早于该时刻的 greeter 列为候选;取不到时刻就不动。 验证:会话查询人为延迟 2 秒,查询前后各起一个同会话、不可读的测试 greeter, 只有解锁前启动的那个被清理。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
已按建议修改(08d4397):收到解锁通知时在调用线程上记下时刻(CLOCK_BOOTTIME 换算成 stat 第 22 字段的时钟计数),只把启动时间早于该时刻的 greeter 列为候选,取不到时刻就不动。补了「解锁后新启动的 greeter 不被选中」的测试,以及该时刻与 /proc 启动时间同一时钟的测试。 验证:会话查询人为延迟 2 秒,查询前后各起一个同会话、不可读的测试 greeter,只有解锁前启动的被清理。Plasma 6.3 X11 实机复测:连续三次远程解锁后 3 秒清理残留 greeter,再锁屏正常,ksmserver 不再报 |
|
08d4397 看过:解锁时在调用线程记 CLOCK_BOOTTIME 截止点、只收早于它的 greeter,并补了定序测试与实机复测,思路正确。请 Codex 复审。 @codex review 🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08d43974d6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let Some(session) = super::display_session() else { return }; | ||
| let seen = greeters(&session, unlocked_at); |
There was a problem hiding this comment.
Carry the observed session ID into the cleanup worker
If User.Display changes from the just-unlocked session A to an already-locked session B while this worker is queued or resolving the display—for example, A logs out while the host remains running—this lookup selects B rather than the session whose LockedHint produced the transition in logind::locked(). B's healthy greeter predates unlocked_at, so both the cutoff and belongs_to accept it, and it is killed after three seconds. A gated probe against the current module reproduced this by changing the session resolver from A to B before releasing discovery. Carry the observed session ID along with the lock-state snapshot instead of looking it up again here.
AGENTS.md reference: AGENTS.md:L274-L274
Useful? React with 👍 / 👎.
ksld 收到 logind 的 Unlock 只给 greeter 发 SIGTERM,等它退出才解锁 (kscreenlocker v6.3.5 ksldapp.cpp requestUnlock / QProcess::finished)。 pam_fprintd.so timeout=-1 时 greeter 退出事件循环后卡在指纹线程上, 会话一直锁定,远控端只看到黑屏和光标,自动解锁返回 Failed。 unlock-session 发出 2 秒后会话仍锁定时,SIGKILL 该会话在请求之前 启动的 greeter;ksld 已置 s_logindExit,进程结束即完成解锁。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
看到 1463a3e:自动解锁 2 秒后会话仍锁定时,SIGKILL 请求前启动的 greeter(引用 kscreenlocker requestUnlock / QProcess::finished 的行为),复用了截止点与会话过滤,思路清楚。 另外 08d4397 的 Codex 复审还有一条 P2 尚未处理,核实成立:清理线程里重新查询 🤖 Generated with Claude Code |
清理线程原先自己查询 User.Display。排队或查询期间图形会话若从刚解锁的 A 变成仍锁定的 B(如 A 注销而服务仍在运行),会选中 B,B 的正常 greeter 早于截止点,3 秒后被误杀。 logind 快照现在把会话 ID 和 LockedHint 一起返回,LockState 记住状态 来自哪个会话;只有同一个会话先锁定、后未锁定才算解锁,并把该会话 ID 连同截止点交给清理线程。图形会话从锁定的 A 换成未锁定的 B 不再触发清理。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
已按建议修改(169db0b):logind 快照把会话 ID 和 比建议多了一点:只有同一个会话先被看到锁定、再被看到未锁定才算解锁。图形会话从锁定的 A 直接换成未锁定的 B 时不再触发清理(之前会被当成一次解锁)。补了对应测试。 自动解锁路径(1463a3e)从发出 验证: |
|
169db0b 看过:解锁时把 logind 快照中的会话 ID 连同截止点交给清理线程、线程内不再查询 @codex review 🤖 Generated with Claude Code |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex 复审 169db0b 无问题、CI 全绿,已 squash 合并,将随下个版本发布。感谢 @wzk4work 的修复和 Plasma 实机复测! 🤖 Generated with Claude Code |
现象
KDE X11(Debian 13 / Plasma 6.3,带指纹的笔记本)上,远程用密码解锁后很快再次锁屏,会得到一个“透明锁屏”:键盘鼠标被抓住,但桌面内容仍然可见,远控端和本机屏幕都一样,指纹灯常亮。此时
ksmserver日志为:原因
对照 kscreenlocker v6.3.5 源码:
Unlocked,ksld 解锁,greeter 退出事件循环。~PamAuthenticator等待指纹 PAM 线程,而pam_fprintd.so timeout=-1只有读到手指才返回,取消只对 PAM 会话回调有效。远程用户按不到指纹,进程一直留着。QProcess::start因旧进程仍在而不启动新的 greeter。这是 kscreenlocker 的问题,本机日志里早于安装本项目就出现过;远控只是让它容易触发。
处理
会话由锁定变为未锁定时,记下本用户的
kscreenlocker_greet(pid + 启动时间),3 秒后仍是同一进程就SIGKILL:s_lockProcessRequestedExit),不会重新锁屏。/proc。验证
cargo test --locked:397 通过。追加:自动解锁停在黑屏
现象
远控端开启“自动解锁被控端”后连接锁屏中的主机,画面全黑,只能看到鼠标光标。主机日志为
Auto unlock result: Failed,会话此后一直是锁定状态。原因
同一个 greeter 挂起,从另一条路径触发(kscreenlocker v6.3.5
ksldapp.cpp):requestUnlock)时只置s_logindExit并给 greeter 发 SIGTERM,真正的解锁在QProcess::finished里。pam_fprintd.so timeout=-1的指纹线程上,进程不结束。处理
unlock_with发出unlock-session2 秒后会话仍锁定时,SIGKILL该 logind 会话里在请求之前启动的 greeter(沿用已有的会话和启动时间筛选)。ksld 已置s_logindExit,进程结束即完成解锁。正常的 greeter 在几毫秒内退出,不受影响;GNOME 等没有kscreenlocker_greet的桌面只是多扫一遍/proc。验证
cargo test --locked:402 通过。Lock screen greeter ignored the unlock request; removed: count=1→Desktop lock state: unlocked→Auto unlock result: Success,约 2 秒进入桌面;断开后自动锁屏每次都启动了新的 greeter。