Commit ac7356eb authored by Eric's avatar Eric

[update] fix bugs

parent 66d9befb
...@@ -58,7 +58,7 @@ type Parser struct { ...@@ -58,7 +58,7 @@ type Parser struct {
cmdOutputParser *CmdParser cmdOutputParser *CmdParser
cmdFilterRules []model.SystemUserFilterRule cmdFilterRules []model.SystemUserFilterRule
closed bool closed chan struct{}
} }
func (p *Parser) initial() { func (p *Parser) initial() {
...@@ -72,6 +72,7 @@ func (p *Parser) initial() { ...@@ -72,6 +72,7 @@ func (p *Parser) initial() {
p.cmdInputParser = NewCmdParser() p.cmdInputParser = NewCmdParser()
p.cmdOutputParser = NewCmdParser() p.cmdOutputParser = NewCmdParser()
p.closed = make(chan struct{})
p.userInputChan = make(chan []byte, 1024) p.userInputChan = make(chan []byte, 1024)
p.userOutputChan = make(chan []byte, 1024) p.userOutputChan = make(chan []byte, 1024)
p.srvInputChan = make(chan []byte, 1024) p.srvInputChan = make(chan []byte, 1024)
...@@ -85,6 +86,8 @@ func (p *Parser) Parse() { ...@@ -85,6 +86,8 @@ func (p *Parser) Parse() {
}() }()
for { for {
select { select {
case <-p.closed:
return
case b, ok := <-p.userInputChan: case b, ok := <-p.userInputChan:
if !ok { if !ok {
return return
...@@ -224,7 +227,6 @@ func (p *Parser) SetCMDFilterRules(rules []model.SystemUserFilterRule) { ...@@ -224,7 +227,6 @@ func (p *Parser) SetCMDFilterRules(rules []model.SystemUserFilterRule) {
} }
func (p *Parser) IsCommandForbidden() (string, bool) { func (p *Parser) IsCommandForbidden() (string, bool) {
fmt.Println("Command is: ", p.command)
for _, rule := range p.cmdFilterRules { for _, rule := range p.cmdFilterRules {
allowed, cmd := rule.Match(p.command) allowed, cmd := rule.Match(p.command)
switch allowed { switch allowed {
...@@ -246,13 +248,16 @@ func (p *Parser) IsRecvState() bool { ...@@ -246,13 +248,16 @@ func (p *Parser) IsRecvState() bool {
} }
func (p *Parser) Close() { func (p *Parser) Close() {
if p.closed { select {
case <-p.closed:
return return
default:
close(p.closed)
} }
close(p.userInputChan) close(p.userInputChan)
close(p.userOutputChan) close(p.userOutputChan)
close(p.srvInputChan) close(p.srvInputChan)
close(p.srvOutputChan) close(p.srvOutputChan)
close(p.cmdRecordChan) close(p.cmdRecordChan)
p.closed = true
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment