mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
fix: command handlers are now atomically locked
This commit is contained in:
parent
3dbc904ddd
commit
e46ea6c9a9
3 changed files with 21 additions and 12 deletions
|
@ -3,14 +3,16 @@ package session
|
|||
import (
|
||||
"github.com/bettercap/readline"
|
||||
"regexp"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type CommandHandler struct {
|
||||
sync.Mutex
|
||||
Name string
|
||||
Description string
|
||||
Completer *readline.PrefixCompleter
|
||||
Parser *regexp.Regexp
|
||||
Exec func(args []string, s *Session) error
|
||||
exec func(args []string, s *Session) error
|
||||
}
|
||||
|
||||
func NewCommandHandler(name string, expr string, desc string, exec func(args []string, s *Session) error) CommandHandler {
|
||||
|
@ -19,7 +21,7 @@ func NewCommandHandler(name string, expr string, desc string, exec func(args []s
|
|||
Description: desc,
|
||||
Completer: nil,
|
||||
Parser: regexp.MustCompile(expr),
|
||||
Exec: exec,
|
||||
exec: exec,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,3 +33,9 @@ func (h *CommandHandler) Parse(line string) (bool, []string) {
|
|||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (h *CommandHandler) Exec(args []string, s *Session) error {
|
||||
h.Lock()
|
||||
defer h.Unlock()
|
||||
return h.exec(args, s)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue