fix 2 races
This commit is contained in:
parent
afbd5f2f69
commit
8b861245c0
2 changed files with 6 additions and 4 deletions
|
@ -17,7 +17,7 @@ type Output struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse needs a reader of the log, and will produce parsed output
|
// Parse needs a reader of the log, and will produce parsed output
|
||||||
func Parse(r io.Reader, parsed chan<- Output) {
|
func Parse(r io.Reader, parsed chan<- Output, onexit chan interface{}) {
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
out, err := outParseLine(scanner.Text())
|
out, err := outParseLine(scanner.Text())
|
||||||
|
@ -25,6 +25,7 @@ func Parse(r io.Reader, parsed chan<- Output) {
|
||||||
parsed <- out
|
parsed <- out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onexit <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var lineRegex = regexp.MustCompile(`^([0-9]{4}/[0-9]{2}/[0-9]{2}) ([0-9:]{8}) \[([^:\[\]]*):([0-9])\] (.*)$`)
|
var lineRegex = regexp.MustCompile(`^([0-9]{4}/[0-9]{2}/[0-9]{2}) ([0-9:]{8}) \[([^:\[\]]*):([0-9])\] (.*)$`)
|
||||||
|
|
|
@ -35,7 +35,8 @@ func RunLiquidsoap(configfile string, kill <-chan struct{}) (<-chan Output, <-ch
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
go Parse(log, out)
|
endparse := make(chan interface{})
|
||||||
|
go Parse(log, out, endparse)
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
proc := cmd.Process
|
proc := cmd.Process
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -43,8 +44,8 @@ func RunLiquidsoap(configfile string, kill <-chan struct{}) (<-chan Output, <-ch
|
||||||
proc.Signal(syscall.SIGINT)
|
proc.Signal(syscall.SIGINT)
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
defer log.Close()
|
<-endparse
|
||||||
err = cmd.Wait()
|
err := cmd.Wait()
|
||||||
close(out)
|
close(out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exit <- End{Err: err}
|
exit <- End{Err: err}
|
||||||
|
|
Loading…
Reference in a new issue