1
0

Implemented sane script validation. WTF did I think later..?

This commit is contained in:
Alexander Andreev 2022-08-29 23:10:39 +04:00
parent 7dd517ea8f
commit f211602a4b
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -1,10 +1,8 @@
package liquidsoap package liquidsoap
import ( import (
"os"
"os/exec" "os/exec"
"syscall" "syscall"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -20,23 +18,21 @@ func NewLiquidsoap(liquidsoapPath, scriptPath string) (*Liquidsoap, error) {
return nil, err 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) cmd := exec.Command(liquidsoapPath, scriptPath)
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
return nil, err 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{ return &Liquidsoap{
command: cmd}, nil command: cmd}, nil
} }