Skip to content

Commit

Permalink
handle errors
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Bachschwell <[email protected]>
  • Loading branch information
s00500 committed May 21, 2021
1 parent 6c4f8e1 commit ed26e4d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion sinks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bufio"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -88,13 +89,41 @@ type HelloVideoSink struct {
}

func (sink HelloVideoSink) StartInstance() (io.WriteCloser, func()) {
logger := log.GetLoggerForPrefix("hellosink")

cmd := exec.Command("/etc/hello_video.bin")
cmd.Env = append(cmd.Env, "LD_LIBRARY_PATH=/opt/vc/lib")
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal("Could not get hellovideo stdin")
logger.Fatal("Could not get hellovideo stdin")
}

stderr, err := cmd.StderrPipe()
if err != nil {
logger.Fatal("Could not get hellovideo stderr")
}

go func() {
errScanner := bufio.NewScanner(stderr)

for errScanner.Scan() {
logger.Error(errScanner.Text())
}
}()

stdout, err := cmd.StdoutPipe()
if err != nil {
logger.Fatal("Could not get hellovideo stdout")
}
go func() {
outScanner := bufio.NewScanner(stdout)
for outScanner.Scan() {
logger.Warn(outScanner.Text())
}
}()

log.MustFatal(cmd.Start())

return stdin, func() {
cmd.Process.Signal(syscall.SIGKILL) // Not ellegant... could try sigterm and wait before...
}
Expand Down

0 comments on commit ed26e4d

Please sign in to comment.