2014-01-10 23:22:39 -05:00
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
2014-01-16 14:59:46 -05:00
|
|
|
"fmt"
|
2014-01-10 23:22:39 -05:00
|
|
|
"github.com/dotcloud/docker/execdriver"
|
2014-01-20 13:52:26 -05:00
|
|
|
"github.com/dotcloud/docker/pkg/mount"
|
2014-01-13 21:36:59 -05:00
|
|
|
"os"
|
2014-01-10 23:22:39 -05:00
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2014-01-15 14:46:25 -05:00
|
|
|
const (
|
|
|
|
DriverName = "chroot"
|
|
|
|
Version = "0.1"
|
|
|
|
)
|
2014-01-13 21:36:59 -05:00
|
|
|
|
|
|
|
func init() {
|
2014-01-15 16:57:07 -05:00
|
|
|
execdriver.RegisterInitFunc(DriverName, func(args *execdriver.InitArgs) error {
|
2014-01-13 21:36:59 -05:00
|
|
|
if err := mount.ForceMount("proc", "proc", "proc", ""); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer mount.ForceUnmount("proc")
|
|
|
|
cmd := exec.Command(args.Args[0], args.Args[1:]...)
|
|
|
|
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stdin = os.Stdin
|
|
|
|
|
|
|
|
return cmd.Run()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-01-10 23:22:39 -05:00
|
|
|
type driver struct {
|
|
|
|
}
|
|
|
|
|
2014-01-13 19:10:23 -05:00
|
|
|
func NewDriver() (*driver, error) {
|
2014-01-10 23:22:39 -05:00
|
|
|
return &driver{}, nil
|
|
|
|
}
|
|
|
|
|
2014-01-13 18:02:12 -05:00
|
|
|
func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallback) (int, error) {
|
2014-01-10 23:22:39 -05:00
|
|
|
params := []string{
|
|
|
|
"chroot",
|
|
|
|
c.Rootfs,
|
|
|
|
"/.dockerinit",
|
2014-01-13 14:13:49 -05:00
|
|
|
"-driver",
|
2014-01-16 18:09:00 -05:00
|
|
|
DriverName,
|
2014-01-10 23:22:39 -05:00
|
|
|
}
|
|
|
|
params = append(params, c.Entrypoint)
|
|
|
|
params = append(params, c.Arguments...)
|
|
|
|
|
|
|
|
var (
|
|
|
|
name = params[0]
|
|
|
|
arg = params[1:]
|
|
|
|
)
|
|
|
|
aname, err := exec.LookPath(name)
|
|
|
|
if err != nil {
|
|
|
|
aname = name
|
|
|
|
}
|
|
|
|
c.Path = aname
|
|
|
|
c.Args = append([]string{name}, arg...)
|
|
|
|
|
|
|
|
if err := c.Start(); err != nil {
|
2014-01-13 18:02:12 -05:00
|
|
|
return -1, err
|
2014-01-10 23:22:39 -05:00
|
|
|
}
|
|
|
|
|
2014-01-13 18:02:12 -05:00
|
|
|
if startCallback != nil {
|
|
|
|
startCallback(c)
|
|
|
|
}
|
|
|
|
|
2014-01-13 19:10:23 -05:00
|
|
|
err = c.Wait()
|
|
|
|
return c.GetExitCode(), err
|
2014-01-10 23:22:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) Kill(p *execdriver.Process, sig int) error {
|
|
|
|
return p.Process.Kill()
|
|
|
|
}
|
|
|
|
|
2014-01-13 20:17:59 -05:00
|
|
|
func (d *driver) Wait(id string) error {
|
|
|
|
panic("Not Implemented")
|
2014-01-10 23:22:39 -05:00
|
|
|
}
|
|
|
|
|
2014-01-15 14:46:25 -05:00
|
|
|
func (d *driver) Info(id string) execdriver.Info {
|
|
|
|
panic("Not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) Name() string {
|
2014-01-16 14:59:46 -05:00
|
|
|
return fmt.Sprintf("%s-%s", DriverName, Version)
|
2014-01-10 23:22:39 -05:00
|
|
|
}
|