From f211602a4b9e9bb2669477262ecc62c65f7999d6 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 29 Aug 2022 23:10:39 +0400 Subject: [PATCH] Implemented sane script validation. WTF did I think later..? --- internal/radio/liquidsoap/liquidsoap.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/internal/radio/liquidsoap/liquidsoap.go b/internal/radio/liquidsoap/liquidsoap.go index 76c7a3a..1f0de69 100644 --- a/internal/radio/liquidsoap/liquidsoap.go +++ b/internal/radio/liquidsoap/liquidsoap.go @@ -1,10 +1,8 @@ package liquidsoap import ( - "os" "os/exec" "syscall" - "time" "github.com/pkg/errors" ) @@ -20,23 +18,21 @@ func NewLiquidsoap(liquidsoapPath, scriptPath string) (*Liquidsoap, error) { return nil, err } + out, err := exec.Command(liquidsoapPath, "--verbose", "-c", scriptPath).CombinedOutput() + if err != nil { + return nil, errors.Wrap(err, "cannot check script") + } + + if len(out) > 0 { + return nil, errors.Errorf("script validation failed: %s", string(out)) + } + cmd := exec.Command(liquidsoapPath, scriptPath) if err := cmd.Start(); err != nil { return nil, err } - // If there are errors in a script this time will be sufficient to wait - // for them to occure. - time.Sleep(4 * time.Second) - - if _, err := os.FindProcess(cmd.Process.Pid); err != nil { - if err_wait := cmd.Wait(); err != nil { - return nil, errors.Wrap(err, err_wait.Error()) - } - return nil, err - } - return &Liquidsoap{ command: cmd}, nil }