Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
| ... | ... |
@@ -53,7 +53,7 @@ type Container struct {
|
| 53 | 53 |
Name string |
| 54 | 54 |
Driver string |
| 55 | 55 |
|
| 56 |
- process *execdriver.Process |
|
| 56 |
+ command *execdriver.Command |
|
| 57 | 57 |
stdout *utils.WriteBroadcaster |
| 58 | 58 |
stderr *utils.WriteBroadcaster |
| 59 | 59 |
stdin io.ReadCloser |
| ... | ... |
@@ -305,8 +305,8 @@ func (container *Container) setupPty() error {
|
| 305 | 305 |
return err |
| 306 | 306 |
} |
| 307 | 307 |
container.ptyMaster = ptyMaster |
| 308 |
- container.process.Stdout = ptySlave |
|
| 309 |
- container.process.Stderr = ptySlave |
|
| 308 |
+ container.command.Stdout = ptySlave |
|
| 309 |
+ container.command.Stderr = ptySlave |
|
| 310 | 310 |
|
| 311 | 311 |
// Copy the PTYs to our broadcasters |
| 312 | 312 |
go func() {
|
| ... | ... |
@@ -318,8 +318,8 @@ func (container *Container) setupPty() error {
|
| 318 | 318 |
|
| 319 | 319 |
// stdin |
| 320 | 320 |
if container.Config.OpenStdin {
|
| 321 |
- container.process.Stdin = ptySlave |
|
| 322 |
- container.process.SysProcAttr.Setctty = true |
|
| 321 |
+ container.command.Stdin = ptySlave |
|
| 322 |
+ container.command.SysProcAttr.Setctty = true |
|
| 323 | 323 |
go func() {
|
| 324 | 324 |
defer container.stdin.Close() |
| 325 | 325 |
utils.Debugf("startPty: begin of stdin pipe")
|
| ... | ... |
@@ -331,10 +331,10 @@ func (container *Container) setupPty() error {
|
| 331 | 331 |
} |
| 332 | 332 |
|
| 333 | 333 |
func (container *Container) setupStd() error {
|
| 334 |
- container.process.Stdout = container.stdout |
|
| 335 |
- container.process.Stderr = container.stderr |
|
| 334 |
+ container.command.Stdout = container.stdout |
|
| 335 |
+ container.command.Stderr = container.stderr |
|
| 336 | 336 |
if container.Config.OpenStdin {
|
| 337 |
- stdin, err := container.process.StdinPipe() |
|
| 337 |
+ stdin, err := container.command.StdinPipe() |
|
| 338 | 338 |
if err != nil {
|
| 339 | 339 |
return err |
| 340 | 340 |
} |
| ... | ... |
@@ -676,7 +676,7 @@ func (container *Container) Start() (err error) {
|
| 676 | 676 |
CpuShares: container.Config.CpuShares, |
| 677 | 677 |
} |
| 678 | 678 |
|
| 679 |
- container.process = &execdriver.Process{
|
|
| 679 |
+ container.command = &execdriver.Command{
|
|
| 680 | 680 |
ID: container.ID, |
| 681 | 681 |
Privileged: container.hostConfig.Privileged, |
| 682 | 682 |
Rootfs: root, |
| ... | ... |
@@ -690,7 +690,7 @@ func (container *Container) Start() (err error) {
|
| 690 | 690 |
Config: driverConfig, |
| 691 | 691 |
Resources: resources, |
| 692 | 692 |
} |
| 693 |
- container.process.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
|
| 693 |
+ container.command.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
|
| 694 | 694 |
|
| 695 | 695 |
// Setup logging of stdout and stderr to disk |
| 696 | 696 |
if err := container.runtime.LogToDisk(container.stdout, container.logPath("json"), "stdout"); err != nil {
|
| ... | ... |
@@ -713,13 +713,13 @@ func (container *Container) Start() (err error) {
|
| 713 | 713 |
} |
| 714 | 714 |
|
| 715 | 715 |
callbackLock := make(chan struct{})
|
| 716 |
- callback := func(process *execdriver.Process) {
|
|
| 717 |
- container.State.SetRunning(process.Pid()) |
|
| 718 |
- if process.Tty {
|
|
| 716 |
+ callback := func(command *execdriver.Command) {
|
|
| 717 |
+ container.State.SetRunning(command.Pid()) |
|
| 718 |
+ if command.Tty {
|
|
| 719 | 719 |
// The callback is called after the process Start() |
| 720 | 720 |
// so we are in the parent process. In TTY mode, stdin/out/err is the PtySlace |
| 721 | 721 |
// which we close here. |
| 722 |
- if c, ok := process.Stdout.(io.Closer); ok {
|
|
| 722 |
+ if c, ok := command.Stdout.(io.Closer); ok {
|
|
| 723 | 723 |
c.Close() |
| 724 | 724 |
} |
| 725 | 725 |
} |
| ... | ... |
@@ -1118,7 +1118,7 @@ func (container *Container) monitor(callback execdriver.StartCallback) error {
|
| 1118 | 1118 |
exitCode int |
| 1119 | 1119 |
) |
| 1120 | 1120 |
|
| 1121 |
- if container.process == nil {
|
|
| 1121 |
+ if container.command == nil {
|
|
| 1122 | 1122 |
// This happends when you have a GHOST container with lxc |
| 1123 | 1123 |
err = container.runtime.WaitGhost(container) |
| 1124 | 1124 |
} else {
|
| ... | ... |
@@ -1210,7 +1210,7 @@ func (container *Container) Kill() error {
|
| 1210 | 1210 |
|
| 1211 | 1211 |
// 2. Wait for the process to die, in last resort, try to kill the process directly |
| 1212 | 1212 |
if err := container.WaitTimeout(10 * time.Second); err != nil {
|
| 1213 |
- if container.process == nil {
|
|
| 1213 |
+ if container.command == nil {
|
|
| 1214 | 1214 |
return fmt.Errorf("lxc-kill failed, impossible to kill the container %s", utils.TruncateID(container.ID))
|
| 1215 | 1215 |
} |
| 1216 | 1216 |
log.Printf("Container %s failed to exit within 10 seconds of lxc-kill %s - trying direct SIGKILL", "SIGKILL", utils.TruncateID(container.ID))
|
| ... | ... |
@@ -36,7 +36,7 @@ func NewDriver() (*driver, error) {
|
| 36 | 36 |
return &driver{}, nil
|
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 |
-func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallback) (int, error) {
|
|
| 39 |
+func (d *driver) Run(c *execdriver.Command, startCallback execdriver.StartCallback) (int, error) {
|
|
| 40 | 40 |
params := []string{
|
| 41 | 41 |
"chroot", |
| 42 | 42 |
c.Rootfs, |
| ... | ... |
@@ -70,7 +70,7 @@ func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallba |
| 70 | 70 |
return c.GetExitCode(), err |
| 71 | 71 |
} |
| 72 | 72 |
|
| 73 |
-func (d *driver) Kill(p *execdriver.Process, sig int) error {
|
|
| 73 |
+func (d *driver) Kill(p *execdriver.Command, sig int) error {
|
|
| 74 | 74 |
return p.Process.Kill() |
| 75 | 75 |
} |
| 76 | 76 |
|
| ... | ... |
@@ -16,7 +16,7 @@ var ( |
| 16 | 16 |
var dockerInitFcts map[string]InitFunc |
| 17 | 17 |
|
| 18 | 18 |
type ( |
| 19 |
- StartCallback func(*Process) |
|
| 19 |
+ StartCallback func(*Command) |
|
| 20 | 20 |
InitFunc func(i *InitArgs) error |
| 21 | 21 |
) |
| 22 | 22 |
|
| ... | ... |
@@ -59,8 +59,8 @@ type Info interface {
|
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 | 61 |
type Driver interface {
|
| 62 |
- Run(c *Process, startCallback StartCallback) (int, error) // Run executes the process and blocks until the process exits and returns the exit code |
|
| 63 |
- Kill(c *Process, sig int) error |
|
| 62 |
+ Run(c *Command, startCallback StartCallback) (int, error) // Run executes the process and blocks until the process exits and returns the exit code |
|
| 63 |
+ Kill(c *Command, sig int) error |
|
| 64 | 64 |
Wait(id string) error // Wait on an out of process...process - lxc ghosts TODO: Rename to reattach, reconnect |
| 65 | 65 |
Name() string // Driver name |
| 66 | 66 |
Info(id string) Info // "temporary" hack (until we move state from core to plugins) |
| ... | ... |
@@ -83,8 +83,8 @@ type Resources struct {
|
| 83 | 83 |
|
| 84 | 84 |
// Process wrapps an os/exec.Cmd to add more metadata |
| 85 | 85 |
// TODO: Rename to Command |
| 86 |
-type Process struct {
|
|
| 87 |
- exec.Cmd |
|
| 86 |
+type Command struct {
|
|
| 87 |
+ exec.Cmd `json:"-"` |
|
| 88 | 88 |
|
| 89 | 89 |
ID string `json:"id"` |
| 90 | 90 |
Privileged bool `json:"privileged"` |
| ... | ... |
@@ -103,7 +103,7 @@ type Process struct {
|
| 103 | 103 |
|
| 104 | 104 |
// Return the pid of the process |
| 105 | 105 |
// If the process is nil -1 will be returned |
| 106 |
-func (c *Process) Pid() int {
|
|
| 106 |
+func (c *Command) Pid() int {
|
|
| 107 | 107 |
if c.Process == nil {
|
| 108 | 108 |
return -1 |
| 109 | 109 |
} |
| ... | ... |
@@ -112,7 +112,7 @@ func (c *Process) Pid() int {
|
| 112 | 112 |
|
| 113 | 113 |
// Return the exit code of the process |
| 114 | 114 |
// if the process has not exited -1 will be returned |
| 115 |
-func (c *Process) GetExitCode() int {
|
|
| 115 |
+func (c *Command) GetExitCode() int {
|
|
| 116 | 116 |
if c.ProcessState == nil {
|
| 117 | 117 |
return -1 |
| 118 | 118 |
} |
| ... | ... |
@@ -30,6 +30,7 @@ func init() {
|
| 30 | 30 |
if err := setupCapabilities(args); err != nil {
|
| 31 | 31 |
return err |
| 32 | 32 |
} |
| 33 |
+ |
|
| 33 | 34 |
if err := setupWorkingDirectory(args); err != nil {
|
| 34 | 35 |
return err |
| 35 | 36 |
} |
| ... | ... |
@@ -37,6 +38,7 @@ func init() {
|
| 37 | 37 |
if err := changeUser(args); err != nil {
|
| 38 | 38 |
return err |
| 39 | 39 |
} |
| 40 |
+ |
|
| 40 | 41 |
path, err := exec.LookPath(args.Args[0]) |
| 41 | 42 |
if err != nil {
|
| 42 | 43 |
log.Printf("Unable to locate %v", args.Args[0])
|
| ... | ... |
@@ -72,7 +74,7 @@ func (d *driver) Name() string {
|
| 72 | 72 |
return fmt.Sprintf("%s-%s", DriverName, version)
|
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 |
-func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallback) (int, error) {
|
|
| 75 |
+func (d *driver) Run(c *execdriver.Command, startCallback execdriver.StartCallback) (int, error) {
|
|
| 76 | 76 |
configPath, err := d.generateLXCConfig(c) |
| 77 | 77 |
if err != nil {
|
| 78 | 78 |
return -1, err |
| ... | ... |
@@ -170,7 +172,7 @@ func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallba |
| 170 | 170 |
return c.GetExitCode(), waitErr |
| 171 | 171 |
} |
| 172 | 172 |
|
| 173 |
-func (d *driver) Kill(c *execdriver.Process, sig int) error {
|
|
| 173 |
+func (d *driver) Kill(c *execdriver.Command, sig int) error {
|
|
| 174 | 174 |
return d.kill(c, sig) |
| 175 | 175 |
} |
| 176 | 176 |
|
| ... | ... |
@@ -198,7 +200,7 @@ func (d *driver) version() string {
|
| 198 | 198 |
return version |
| 199 | 199 |
} |
| 200 | 200 |
|
| 201 |
-func (d *driver) kill(c *execdriver.Process, sig int) error {
|
|
| 201 |
+func (d *driver) kill(c *execdriver.Command, sig int) error {
|
|
| 202 | 202 |
output, err := exec.Command("lxc-kill", "-n", c.ID, strconv.Itoa(sig)).CombinedOutput()
|
| 203 | 203 |
if err != nil {
|
| 204 | 204 |
return fmt.Errorf("Err: %s Output: %s", err, output)
|
| ... | ... |
@@ -206,7 +208,7 @@ func (d *driver) kill(c *execdriver.Process, sig int) error {
|
| 206 | 206 |
return nil |
| 207 | 207 |
} |
| 208 | 208 |
|
| 209 |
-func (d *driver) waitForStart(c *execdriver.Process, waitLock chan struct{}) error {
|
|
| 209 |
+func (d *driver) waitForStart(c *execdriver.Command, waitLock chan struct{}) error {
|
|
| 210 | 210 |
var ( |
| 211 | 211 |
err error |
| 212 | 212 |
output []byte |
| ... | ... |
@@ -302,8 +304,8 @@ func rootIsShared() bool {
|
| 302 | 302 |
return true |
| 303 | 303 |
} |
| 304 | 304 |
|
| 305 |
-func (d *driver) generateLXCConfig(p *execdriver.Process) (string, error) {
|
|
| 306 |
- root := path.Join(d.root, "containers", p.ID, "config.lxc") |
|
| 305 |
+func (d *driver) generateLXCConfig(c *execdriver.Command) (string, error) {
|
|
| 306 |
+ root := path.Join(d.root, "containers", c.ID, "config.lxc") |
|
| 307 | 307 |
fo, err := os.Create(root) |
| 308 | 308 |
if err != nil {
|
| 309 | 309 |
return "", err |
| ... | ... |
@@ -311,10 +313,10 @@ func (d *driver) generateLXCConfig(p *execdriver.Process) (string, error) {
|
| 311 | 311 |
defer fo.Close() |
| 312 | 312 |
|
| 313 | 313 |
if err := LxcTemplateCompiled.Execute(fo, struct {
|
| 314 |
- *execdriver.Process |
|
| 314 |
+ *execdriver.Command |
|
| 315 | 315 |
AppArmor bool |
| 316 | 316 |
}{
|
| 317 |
- Process: p, |
|
| 317 |
+ Command: c, |
|
| 318 | 318 |
AppArmor: d.apparmor, |
| 319 | 319 |
}); err != nil {
|
| 320 | 320 |
return "", err |
| ... | ... |
@@ -37,14 +37,14 @@ func TestLXCConfig(t *testing.T) {
|
| 37 | 37 |
if err != nil {
|
| 38 | 38 |
t.Fatal(err) |
| 39 | 39 |
} |
| 40 |
- process := &execdriver.Process{
|
|
| 40 |
+ command := &execdriver.Command{
|
|
| 41 | 41 |
ID: "1", |
| 42 | 42 |
Resources: &execdriver.Resources{
|
| 43 | 43 |
Memory: int64(mem), |
| 44 | 44 |
CpuShares: int64(cpu), |
| 45 | 45 |
}, |
| 46 | 46 |
} |
| 47 |
- p, err := driver.generateLXCConfig(process) |
|
| 47 |
+ p, err := driver.generateLXCConfig(command) |
|
| 48 | 48 |
if err != nil {
|
| 49 | 49 |
t.Fatal(err) |
| 50 | 50 |
} |
| ... | ... |
@@ -68,7 +68,7 @@ func TestCustomLxcConfig(t *testing.T) {
|
| 68 | 68 |
if err != nil {
|
| 69 | 69 |
t.Fatal(err) |
| 70 | 70 |
} |
| 71 |
- process := &execdriver.Process{
|
|
| 71 |
+ command := &execdriver.Command{
|
|
| 72 | 72 |
ID: "1", |
| 73 | 73 |
Privileged: false, |
| 74 | 74 |
Config: []string{
|
| ... | ... |
@@ -77,7 +77,7 @@ func TestCustomLxcConfig(t *testing.T) {
|
| 77 | 77 |
}, |
| 78 | 78 |
} |
| 79 | 79 |
|
| 80 |
- p, err := driver.generateLXCConfig(process) |
|
| 80 |
+ p, err := driver.generateLXCConfig(command) |
|
| 81 | 81 |
if err != nil {
|
| 82 | 82 |
t.Fatal(err) |
| 83 | 83 |
} |
| ... | ... |
@@ -802,11 +802,11 @@ func (runtime *Runtime) Diff(container *Container) (archive.Archive, error) {
|
| 802 | 802 |
} |
| 803 | 803 |
|
| 804 | 804 |
func (runtime *Runtime) Run(c *Container, startCallback execdriver.StartCallback) (int, error) {
|
| 805 |
- return runtime.execDriver.Run(c.process, startCallback) |
|
| 805 |
+ return runtime.execDriver.Run(c.command, startCallback) |
|
| 806 | 806 |
} |
| 807 | 807 |
|
| 808 | 808 |
func (runtime *Runtime) Kill(c *Container, sig int) error {
|
| 809 |
- return runtime.execDriver.Kill(c.process, sig) |
|
| 809 |
+ return runtime.execDriver.Kill(c.command, sig) |
|
| 810 | 810 |
} |
| 811 | 811 |
|
| 812 | 812 |
func (runtime *Runtime) WaitGhost(c *Container) error {
|
| ... | ... |
@@ -50,14 +50,16 @@ func SysInit() {
|
| 50 | 50 |
os.Exit(1) |
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 |
- // Get cmdline arguments |
|
| 54 |
- user := flag.String("u", "", "username or uid")
|
|
| 55 |
- gateway := flag.String("g", "", "gateway address")
|
|
| 56 |
- ip := flag.String("i", "", "ip address")
|
|
| 57 |
- workDir := flag.String("w", "", "workdir")
|
|
| 58 |
- privileged := flag.Bool("privileged", false, "privileged mode")
|
|
| 59 |
- mtu := flag.Int("mtu", 1500, "interface mtu")
|
|
| 60 |
- driver := flag.String("driver", "", "exec driver")
|
|
| 53 |
+ var ( |
|
| 54 |
+ // Get cmdline arguments |
|
| 55 |
+ user = flag.String("u", "", "username or uid")
|
|
| 56 |
+ gateway = flag.String("g", "", "gateway address")
|
|
| 57 |
+ ip = flag.String("i", "", "ip address")
|
|
| 58 |
+ workDir = flag.String("w", "", "workdir")
|
|
| 59 |
+ privileged = flag.Bool("privileged", false, "privileged mode")
|
|
| 60 |
+ mtu = flag.Int("mtu", 1500, "interface mtu")
|
|
| 61 |
+ driver = flag.String("driver", "", "exec driver")
|
|
| 62 |
+ ) |
|
| 61 | 63 |
flag.Parse() |
| 62 | 64 |
|
| 63 | 65 |
// Get env |