diff options
author | euer <root@euer.krebsco.de> | 2012-12-20 15:53:41 +0100 |
---|---|---|
committer | euer <root@euer.krebsco.de> | 2012-12-20 15:53:41 +0100 |
commit | 17ffe40523144a60d4297cfb18c3b5fdaffa84af (patch) | |
tree | 6c1104cffe5e3d581d4924edc74f4626d208970d /hyper/process/src | |
parent | a283809283e3e0606271ae263ff8d4ccbd990af6 (diff) |
//{hyper,json} -> //sandbox
//{icecrab,kachelmann,meinsack} -> //god
//host -> //punani/host
Diffstat (limited to 'hyper/process/src')
-rw-r--r-- | hyper/process/src/hyper/process/Makefile | 11 | ||||
-rw-r--r-- | hyper/process/src/hyper/process/process.go | 132 |
2 files changed, 0 insertions, 143 deletions
diff --git a/hyper/process/src/hyper/process/Makefile b/hyper/process/src/hyper/process/Makefile deleted file mode 100644 index 7ecda716..00000000 --- a/hyper/process/src/hyper/process/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include ${GOROOT}/src/Make.inc - -TARG=hyper/process - -GOFILES=\ - process.go\ - -#DEPS=\ -# gorilla.googlecode.com/hg/gorilla/context\ - -include ${GOROOT}/src/Make.pkg diff --git a/hyper/process/src/hyper/process/process.go b/hyper/process/src/hyper/process/process.go deleted file mode 100644 index 18cf55fb..00000000 --- a/hyper/process/src/hyper/process/process.go +++ /dev/null @@ -1,132 +0,0 @@ -package hyper - -import "fmt" -import "http" -import "bytes" -import "json" -import "os" - -type Process struct { - Path string `json:"path"` - Argv []string `json:"argv"` - Envp map[string]string `json:"envp"` - //Stdin string `json:"stdin"` - Stdout string `json:"stdout"` - Stderr string `json:"stderr"` - process *os.Process - process_stdin *os.File - process_stdout *os.File - process_stderr *os.File - id string - client http.Client -} - -func (p *Process) Id() string { - return p.id -} - -func NewProcess(req *http.Request) (*Process, os.Error) { - body := make([]byte, 4096) - _, err := req.Body.Read(body) - if err != nil { - return nil, err - } - - body = bytes.TrimRight(body, string([]byte{0})) - - var p Process - - if err := json.Unmarshal(body, &p); err != nil { - return nil, err - } - - p.id = gensym() - - if err := p.Start(); err != nil { - return nil, err - } - - return &p, nil -} - -func (hp *Process) Write(b []byte) { - n, err := hp.process_stdin.Write(b) - if err != nil { - fmt.Printf("Write: %s\n", err) - } else { - fmt.Printf("Wrote: %d bytes\n", n) - } -} - -func (hp *Process) Start() os.Error { - var name = hp.Path //os.Args[1] //"/usr/b" - var argv = hp.Argv //os.Args[1:] //[]string{ "bc" } - //var chroot = false - //var dir = "/var/empty" - var files [3][2]*os.File - var err os.Error - - for i, _ := range files { - files[i][0], files[i][1], err = os.Pipe() - if err != nil { - return err - } - } - - var env []string - for k, v := range hp.Envp { - env = append(env, fmt.Sprintf("%s=%s", k, v)) - } - - var attr = &os.ProcAttr{ - //Dir: dir, - Env: env, //os.Environ(), - Files: []*os.File{ files[0][0], files[1][1], files[2][1]}, - } - - //var foo, _ = json.Marshal(attr) - //fmt.Printf("%s\n", foo) - - hp.process, err = os.StartProcess(name, argv, attr) - if err != nil { - return err - } - - hp.process_stdin = files[0][1] - hp.process_stdout = files[1][0] - hp.process_stderr = files[2][0] - - for _, file := range attr.Files { - file.Close() - } - - go hp.reader(hp.process_stdout, hp.Stdout) - go hp.reader(hp.process_stderr, hp.Stderr) - return nil -} - -func (p *Process) reader(file *os.File, url string) { - var b []byte = make([]byte, 1024) - var err os.Error = nil - for err == nil { - var n int - n, err = file.Read(b) - fmt.Printf("data: %d, %s\n", n, b) - - res, err := p.client.Post(url, "application/octet-stream", bytes.NewBuffer(b)) - res = res - if err != nil { - fmt.Printf("EE: %s: %s\n", url, err) - } - } -} - -func gensym() string { - f, _ := os.Open("/dev/urandom") - b := make([]byte, 16) - f.Read(b) - f.Close() - uuid := fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]) - return uuid -} - |