diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-01-17 14:13:50 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-01-17 14:13:50 +0900 |
commit | 0a22a1dcb35601f5fe4f1da4a5fabd5854e62d09 (patch) | |
tree | 340bf6d094a8e799c58d74ccff9107cbf4cf0e5f | |
parent | 175b21901d057ff927ee96b9888872e16f1bea63 (diff) | |
download | poe-0a22a1dcb35601f5fe4f1da4a5fabd5854e62d09.tar.gz |
sandbox-go: change json schema
-rw-r--r-- | app/models/compiler.rb | 7 | ||||
-rw-r--r-- | sandbox-go/plan.json | 9 | ||||
-rw-r--r-- | sandbox-go/src/child.go | 10 | ||||
-rw-r--r-- | sandbox-go/src/main.go | 12 | ||||
-rw-r--r-- | sandbox-go/src/playground.go | 3 |
5 files changed, 27 insertions, 14 deletions
diff --git a/app/models/compiler.rb b/app/models/compiler.rb index 91113ba..d6d1ba3 100644 --- a/app/models/compiler.rb +++ b/app/models/compiler.rb @@ -28,9 +28,12 @@ class Compiler < ApplicationRecord plan = { "base" => Rails.root.join("playground/base").to_s, - "environment" => Rails.root.join("playground").join(language).join(version).to_s, "source" => sf.path, - "command" => Shellwords.split(command_line) + "extra" => [], + "compiler" => { + "overlay" => Rails.root.join("playground").join(language).join(version).to_s, + "command" => Shellwords.split(command_line) + } } pf.write(JSON.generate(plan)) pf.fsync diff --git a/sandbox-go/plan.json b/sandbox-go/plan.json index e4b7b45..b0bcd5b 100644 --- a/sandbox-go/plan.json +++ b/sandbox-go/plan.json @@ -1,6 +1,9 @@ { "base" : "/work/poe/playground/base", - "environment" : "/work/poe/playground/ruby/2.3.0", - "source" : "plan.txt", - "command" : ["/usr/bin/echo", "test"] + "source" : "plan.json", + "extra" : ["-v"], + "compiler" : { + "overlay" : "/work/poe/playground/ruby/2.3.0", + "command" : ["/opt/bin/ruby", "EXTRA", "PROGRAM"] + } } diff --git a/sandbox-go/src/child.go b/sandbox-go/src/child.go index 1611c22..3195004 100644 --- a/sandbox-go/src/child.go +++ b/sandbox-go/src/child.go @@ -115,12 +115,14 @@ func doChild(rootdir string, progfile string, plan plan, stdin_fd, stdout_fd, st "LOGNAME=" + username, } - cmdl := make([]string, len(plan.Command)) - for i, arg := range plan.Command { + cmdl := make([]string, 0, len(plan.Compiler.Command) + len(plan.Extra) - 1) + for _, arg := range plan.Compiler.Command { if arg == "PROGRAM" { - cmdl[i] = progfile + cmdl = append(cmdl, progfile) + } else if arg == "EXTRA" { + cmdl = append(cmdl, plan.Extra...) } else { - cmdl[i] = arg + cmdl = append(cmdl, arg) } } diff --git a/sandbox-go/src/main.go b/sandbox-go/src/main.go index 0a01122..4c49552 100644 --- a/sandbox-go/src/main.go +++ b/sandbox-go/src/main.go @@ -9,12 +9,16 @@ import ( "runtime" "syscall" ) +type compiler struct { + Overlay string + Command []string +} type plan struct { - Source string - Command []string Base string - Environment string + Source string + Extra []string + Compiler compiler } type poeExitReason int @@ -66,7 +70,7 @@ func main() { } runtime.UnlockOSThread() - rootdir, errx := PlaygroundCreate(plan.Base, plan.Environment) + rootdir, errx := PlaygroundCreate(plan.Base, plan.Compiler.Overlay) if errx != nil { poePanic(errx, "playground_create failed") } diff --git a/sandbox-go/src/playground.go b/sandbox-go/src/playground.go index 8170326..3f31442 100644 --- a/sandbox-go/src/playground.go +++ b/sandbox-go/src/playground.go @@ -78,7 +78,8 @@ func PlaygroundDestroy() error { mergeddir := basedir + "/merged" syscall.Unmount(mergeddir, syscall.MNT_DETACH) // ignore error syscall.Unmount(basedir, syscall.MNT_DETACH) // ignore error - os.Remove(basedir) // ignore error + + os.RemoveAll(basedir) // ignore error return nil } |