From c7e40344079d8286c2fda9ddea33f95078b7128c Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 16 May 2019 12:56:25 +0800 Subject: [PATCH] =?UTF-8?q?:lock:=20#296=20=E9=99=90=E5=88=B6=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- output/run.go | 3 +-- playground/run.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/output/run.go b/output/run.go index d50db3d..e4312c2 100644 --- a/output/run.go +++ b/output/run.go @@ -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() diff --git a/playground/run.go b/playground/run.go index 031fbe6..551f13e 100644 --- a/playground/run.go +++ b/playground/run.go @@ -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 {