Skip to content

Commit

Permalink
fix: dde-session-daemon panic error
Browse files Browse the repository at this point in the history
recordEventLoop can not be in NewShortcutManager, recordEventLoop and
NewShortcutManager is in different goroutine, recordEventLoop maybe
access NewShortcutManager data mistakely, that will be panic.

Log:
  • Loading branch information
dengbo11 committed Nov 2, 2023
1 parent ee0afe8 commit 220d49c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
3 changes: 2 additions & 1 deletion keybinding/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package keybinding

import (
"github.com/linuxdeepin/go-lib/log"
"github.com/linuxdeepin/dde-daemon/keybinding/shortcuts"
"github.com/linuxdeepin/dde-daemon/loader"
"github.com/linuxdeepin/go-lib/log"
)

func init() {
Expand Down Expand Up @@ -77,6 +77,7 @@ func (d *Daemon) Start() error {

m.eliminateKeystrokeConflict()
m.shortcutManager.EventLoop()
m.shortcutManager.RecordEventLoop()
}()

return nil
Expand Down
10 changes: 6 additions & 4 deletions keybinding/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,12 @@ func (m *Manager) handleKeyEvent(ev *shortcuts.KeyEvent) {
return
}

if handler := m.handlers[int(action.Type)]; handler != nil {
handler(ev)
} else {
logger.Warning("handler is nil")
if len(m.handlers) > 0 {
if handler := m.handlers[int(action.Type)]; handler != nil {
handler(ev)
} else {
logger.Warning("handler is nil")
}
}
}

Expand Down
15 changes: 6 additions & 9 deletions keybinding/shortcuts/shortcut_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,7 @@ func NewShortcutManager(conn *x.Conn, keySymbols *keysyms.KeySymbols, eventCb Ke
}
// init record
err := ss.initRecord()
if err == nil {
logger.Debug("start record event loop")
go ss.recordEventLoop()
} else {
if err != nil {
logger.Warning("init record failed: ", err)
}

Expand All @@ -207,7 +204,7 @@ func NewShortcutManager(conn *x.Conn, keySymbols *keysyms.KeySymbols, eventCb Ke
return ss
}

func (sm *ShortcutManager) recordEventLoop() {
func (sm *ShortcutManager) RecordEventLoop() {
// enable context
cookie := record.EnableContext(sm.dataConn, sm.recordContext)

Expand Down Expand Up @@ -703,8 +700,8 @@ func (sm *ShortcutManager) SetAllModKeysReleasedCallback(cb func()) {
sm.xRecordEventHandler.allModKeysReleasedCb = cb
}

//get Active Window pid
//注意: 从D-BUS启动dde-system-daemon的时候x会取不到环境变量,只能把获取pid放到dde-session-daemon
// get Active Window pid
// 注意: 从D-BUS启动dde-system-daemon的时候x会取不到环境变量,只能把获取pid放到dde-session-daemon
func (sm *ShortcutManager) getActiveWindowPid() (uint32, error) {
activeWin, err := ewmh.GetActiveWindow(sm.conn).Reply(sm.conn)
if err != nil {
Expand All @@ -731,7 +728,7 @@ func (sm *ShortcutManager) isPidVirtualMachine(pid uint32) (bool, error) {
return ret, nil
}

//初始化go-dbus-factory system DBUS : org.deepin.dde.Daemon1
// 初始化go-dbus-factory system DBUS : org.deepin.dde.Daemon1
func (sm *ShortcutManager) initSysDaemon() error {
sysBus, err := dbus.SystemBus()
if err != nil {
Expand Down Expand Up @@ -1091,7 +1088,7 @@ func (sm *ShortcutManager) AddCustom(csm *CustomShortcutManager, wmObj wm.Wm) {
logger.Warning("failed to setShortForWayland:", err)
continue
}
sm.WaylandCustomShortCutMap[id + "-cs"] = cmd
sm.WaylandCustomShortCutMap[id+"-cs"] = cmd
cs := newCustomShort(id, id, keystrokesStrv, wmObj, csm)
sm.addWithoutLock(cs)
}
Expand Down

0 comments on commit 220d49c

Please sign in to comment.