🔒 #296 限制执行时间
This commit is contained in:
parent
6bc8f32e85
commit
c7e4034407
|
@ -63,12 +63,11 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
|||
var cmd *exec.Cmd
|
||||
if conf.Docker {
|
||||
fileName := filepath.Base(filePath)
|
||||
cmd = exec.Command("docker", "run", "--rm", "-v", filePath+":/"+fileName, "busybox", "timeout", "10", "/"+fileName)
|
||||
cmd = exec.Command("timeout", "5", "docker", "run", "--rm", "-v", filePath+":/"+fileName, "busybox", "/"+fileName)
|
||||
} else {
|
||||
cmd = exec.Command(filePath)
|
||||
curDir := filepath.Dir(filePath)
|
||||
cmd.Dir = curDir
|
||||
logger.Warnf("Executing user's program [" + filePath + "] without docker sandbox")
|
||||
}
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
|
|
|
@ -20,8 +20,11 @@ import (
|
|||
"math/rand"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/b3log/wide/conf"
|
||||
|
||||
"github.com/b3log/wide/output"
|
||||
"github.com/b3log/wide/session"
|
||||
"github.com/b3log/wide/util"
|
||||
|
@ -58,7 +61,15 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
filePath := args["executable"].(string)
|
||||
|
||||
cmd := exec.Command(filePath)
|
||||
var cmd *exec.Cmd
|
||||
if conf.Docker {
|
||||
fileName := filepath.Base(filePath)
|
||||
cmd = exec.Command("timeout", "5", "docker", "run", "--rm", "-v", filePath+":/"+fileName, "busybox", "/"+fileName)
|
||||
} else {
|
||||
cmd = exec.Command(filePath)
|
||||
curDir := filepath.Dir(filePath)
|
||||
cmd.Dir = curDir
|
||||
}
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if nil != err {
|
||||
|
|
Loading…
Reference in New Issue