Implemented sane script validation. WTF did I think later..?
This commit is contained in:
parent
7dd517ea8f
commit
f211602a4b
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user