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