device/raspistill/imp_release.go: improve error checking routine and removed unused const

This commit is contained in:
Saxon Nelson-Milton 2021-01-21 13:14:45 +10:30
parent 45c019a062
commit 8a792099a5
1 changed files with 12 additions and 11 deletions

View File

@ -33,7 +33,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"bufio"
"os/exec"
"strings"
@ -73,7 +73,6 @@ func (r *Raspistill) stop() error {
}
func (r *Raspistill) start() error {
const disabled = "0"
args := []string{
"--output", "-",
"--nopreview",
@ -99,23 +98,25 @@ func (r *Raspistill) start() error {
return fmt.Errorf("could not pipe command error: %w", err)
}
go func() {
errScnr := bufio.NewScanner(stderr)
for {
select {
case <-r.done:
r.log.Info("raspistill.Stop() called, finished checking stderr")
return
default:
buf, err := ioutil.ReadAll(stderr)
if err != nil {
r.log.Error("could not read stderr", "error", err)
return
}
if len(buf) != 0 {
r.log.Error("error from raspistill stderr", "error", string(buf))
return
if errScnr.Scan() {
r.log.Error("error line from raspistill stderr","error",errScnr.Text())
continue
}
err := errScnr.Err()
if err != nil {
r.log.Error("error from stderr scan","error",err)
}
}
}()