增加sandbox对windows编译支持,现在默认是linux的实现,windows直接编译报错
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -89,9 +88,7 @@ func (s *LocalSandbox) Execute(ctx context.Context, config *ExecuteConfig) (*Exe
|
|||||||
cmd.Env = s.buildEnvironment(config.Env)
|
cmd.Env = s.buildEnvironment(config.Env)
|
||||||
|
|
||||||
// Setup process group for cleanup
|
// Setup process group for cleanup
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
setupProcessGroup(cmd)
|
||||||
Setpgid: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
cmd.Stdout = &stdout
|
cmd.Stdout = &stdout
|
||||||
@@ -115,7 +112,7 @@ func (s *LocalSandbox) Execute(ctx context.Context, config *ExecuteConfig) (*Exe
|
|||||||
if execCtx.Err() == context.DeadlineExceeded {
|
if execCtx.Err() == context.DeadlineExceeded {
|
||||||
// Kill the process group
|
// Kill the process group
|
||||||
if cmd.Process != nil {
|
if cmd.Process != nil {
|
||||||
syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
killProcessGroup(cmd)
|
||||||
}
|
}
|
||||||
result.Killed = true
|
result.Killed = true
|
||||||
result.Error = ErrTimeout.Error()
|
result.Error = ErrTimeout.Error()
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
package sandbox
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupProcessGroup(cmd *exec.Cmd) {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||||
|
Setpgid: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func killProcessGroup(cmd *exec.Cmd) {
|
||||||
|
if cmd.Process != nil {
|
||||||
|
syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package sandbox
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupProcessGroup(cmd *exec.Cmd) {
|
||||||
|
// Windows does not support Setpgid; process groups are managed via Job Objects
|
||||||
|
}
|
||||||
|
|
||||||
|
func killProcessGroup(cmd *exec.Cmd) {
|
||||||
|
if cmd.Process != nil {
|
||||||
|
cmd.Process.Kill()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user