fix 2 races

This commit is contained in:
boyska 2017-07-30 01:47:28 +02:00
parent afbd5f2f69
commit 8b861245c0
2 changed files with 6 additions and 4 deletions

View file

@ -17,7 +17,7 @@ type Output struct {
}
// 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)
for scanner.Scan() {
out, err := outParseLine(scanner.Text())
@ -25,6 +25,7 @@ func Parse(r io.Reader, parsed chan<- Output) {
parsed <- out
}
}
onexit <- struct{}{}
}
var lineRegex = regexp.MustCompile(`^([0-9]{4}/[0-9]{2}/[0-9]{2}) ([0-9:]{8}) \[([^:\[\]]*):([0-9])\] (.*)$`)

View file

@ -35,7 +35,8 @@ func RunLiquidsoap(configfile string, kill <-chan struct{}) (<-chan Output, <-ch
if err != nil {
return nil, nil, err
}
go Parse(log, out)
endparse := make(chan interface{})
go Parse(log, out, endparse)
err = cmd.Start()
proc := cmd.Process
go func() {
@ -43,8 +44,8 @@ func RunLiquidsoap(configfile string, kill <-chan struct{}) (<-chan Output, <-ch
proc.Signal(syscall.SIGINT)
}()
go func() {
defer log.Close()
err = cmd.Wait()
<-endparse
err := cmd.Wait()
close(out)
if err != nil {
exit <- End{Err: err}