mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-21 09:28:14 +00:00
fix(plugins): 修复两处预存缺陷(agentcli 临界区 / localuse 脚本转义)
agentcli cleanupLoop: 持锁期间为每个过期终端 go func 调 term.Close()(内部会 Kill 进程并等 <-t.done),临界区被拉长且与 TerminalSession 退出路径交错。改为持锁 只做筛选与摘除,锁外再逐个关闭。 localuse 脚本转义(两处真实 bug): 1. AppleScript 注入:handleScreensue 只把 `"` 转义为 `\"`,未转义 `\`。 内容结尾的反斜杠会吃掉闭合引号,使后续内容逃逸出字符串字面量。 改为 escapeAppleScriptString:**先转义反斜杠再转义双引号**(顺序 不可颠倒,否则刚插入的反斜杠会被二次转义)。 2. PowerShell 路径被错误加倍反斜杠:handleScreensee 把 Windows 临时 路径的 `\` 写成 `\\`。但 PowerShell 单引号串里反斜杠是普通字符 (转义符是反引号),加倍会让截图保存到错误路径。 新增 psSingleQuote 统一处理,并把 4 处零散的 `ReplaceAll(x,"'","''")` 收敛到该 helper。
This commit is contained in:
@ -993,24 +993,28 @@ func (p *Plugin) cleanupLoop(s *sdk.PluginSDK) {
|
||||
case <-p.stopCh:
|
||||
return
|
||||
case <-ticker.C:
|
||||
// 先持锁筛选出待关闭的终终并移出 map,再在锁外逐个关闭。
|
||||
// 旧实现在持锁期间 go func 调 term.Close()(内部会 Kill 进程并等
|
||||
// <-t.done),临界区被拉长且与 TerminalSession 的退出路径交错。
|
||||
var expired []*TerminalSession
|
||||
p.mu.Lock()
|
||||
for id, t := range p.sessions {
|
||||
if t.IsExpired() {
|
||||
switch {
|
||||
case t.IsExpired():
|
||||
log.Printf("[agentcli] cleanup: terminal %s expired", id)
|
||||
delete(p.sessions, id)
|
||||
go func(term *TerminalSession) {
|
||||
term.Close()
|
||||
}(t)
|
||||
}
|
||||
if !terminalRunning(t) {
|
||||
case !terminalRunning(t):
|
||||
log.Printf("[agentcli] cleanup: terminal %s process exited", id)
|
||||
delete(p.sessions, id)
|
||||
go func(term *TerminalSession) {
|
||||
term.Close()
|
||||
}(t)
|
||||
default:
|
||||
continue
|
||||
}
|
||||
delete(p.sessions, id)
|
||||
expired = append(expired, t)
|
||||
}
|
||||
p.mu.Unlock()
|
||||
|
||||
for _, t := range expired {
|
||||
go func(term *TerminalSession) { term.Close() }(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user