🔒 #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
|
var cmd *exec.Cmd
|
||||||
if conf.Docker {
|
if conf.Docker {
|
||||||
fileName := filepath.Base(filePath)
|
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 {
|
} else {
|
||||||
cmd = exec.Command(filePath)
|
cmd = exec.Command(filePath)
|
||||||
curDir := filepath.Dir(filePath)
|
curDir := filepath.Dir(filePath)
|
||||||
cmd.Dir = curDir
|
cmd.Dir = curDir
|
||||||
logger.Warnf("Executing user's program [" + filePath + "] without docker sandbox")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
|
|
|
@ -20,8 +20,11 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/b3log/wide/conf"
|
||||||
|
|
||||||
"github.com/b3log/wide/output"
|
"github.com/b3log/wide/output"
|
||||||
"github.com/b3log/wide/session"
|
"github.com/b3log/wide/session"
|
||||||
"github.com/b3log/wide/util"
|
"github.com/b3log/wide/util"
|
||||||
|
@ -58,7 +61,15 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
filePath := args["executable"].(string)
|
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()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
Loading…
Reference in New Issue