forked from hyperhq/runv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshim.go
More file actions
65 lines (59 loc) · 1.3 KB
/
shim.go
File metadata and controls
65 lines (59 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/codegangsta/cli"
"github.com/hyperhq/runv/lib/term"
)
var shimCommand = cli.Command{
Name: "shim",
Usage: "internal command for proxy changes to the container/process",
Flags: []cli.Flag{
cli.StringFlag{
Name: "container",
},
cli.StringFlag{
Name: "process",
},
cli.StringFlag{
Name: "proxy-exit-code",
},
cli.StringFlag{
Name: "proxy-signal",
},
cli.StringFlag{
Name: "proxy-winsize",
},
},
Action: func(context *cli.Context) {
root := context.GlobalString("root")
container := context.String("container")
process := context.String("process")
c := getClient(filepath.Join(root, container, "namespace/namespaced.sock"))
exitcode := -1
if context.Bool("proxy-exit-code") {
defer func() { os.Exit(exitcode) }()
}
if context.Bool("proxy-winsize") {
s, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
fmt.Printf("error %v\n", err)
return
}
defer term.RestoreTerminal(os.Stdin.Fd(), s)
monitorTtySize(c, container, process)
}
if context.Bool("proxy-signal") {
// TODO
}
// wait until exit
evChan := containerEvents(c, container)
for e := range evChan {
if e.Type == "exit" && e.Pid == process {
exitcode = int(e.Status)
break
}
}
},
}