diff --git a/liquidsoap/parser.go b/liquidsoap/parser.go index 3d09235..f9ca67e 100644 --- a/liquidsoap/parser.go +++ b/liquidsoap/parser.go @@ -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])\] (.*)$`) diff --git a/liquidsoap/spawn.go b/liquidsoap/spawn.go index 9b7a6d3..6987cb1 100644 --- a/liquidsoap/spawn.go +++ b/liquidsoap/spawn.go @@ -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}