-func OpenAndReadAll(filename string, log_chan chan<- string) ([]byte, error) {
- in, err := os.Open(filename)
- if err != nil {
- if log_chan != nil {
- log_chan <- fmt.Sprintf("crunchstat: open %s: %s", filename, err)
+func CopyPipeToChildLog(in io.ReadCloser, done chan<- bool) {
+ reader := bufio.NewReaderSize(in, MaxLogLine)
+ var prefix string
+ for {
+ line, isPrefix, err := reader.ReadLine()
+ if err == io.EOF {
+ break
+ } else if err != nil {
+ statLog.Fatal("error reading child stderr:", err)
+ }
+ var suffix string
+ if isPrefix {
+ suffix = "[...]"
+ }
+ childLog.Print(prefix, string(line), suffix)
+ // Set up prefix for following line
+ if isPrefix {
+ prefix = "[...]"
+ } else {
+ prefix = ""