mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
7321067176
This changes the way the exec drivers work by not specifing a -driver flag on reexec. For each of the exec drivers they register their own functions that will be matched aginst the argv 0 on exec and called if they match. This also allows any functionality to be added to docker so that the binary can be reexec'd and any type of function can be called. I moved the flag parsing on docker exec to the specific initializers so that the implementations do not bleed into one another. This also allows for more flexability within reexec initializers to specify their own flags and options. Signed-off-by: Michael Crosby <michael@docker.com>
65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
// +build linux
|
|
|
|
package native
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"github.com/docker/docker/reexec"
|
|
"github.com/docker/libcontainer"
|
|
"github.com/docker/libcontainer/namespaces"
|
|
"github.com/docker/libcontainer/syncpipe"
|
|
)
|
|
|
|
func init() {
|
|
reexec.Register(DriverName, initializer)
|
|
}
|
|
|
|
func initializer() {
|
|
runtime.LockOSThread()
|
|
|
|
var (
|
|
pipe = flag.Int("pipe", 0, "sync pipe fd")
|
|
console = flag.String("console", "", "console (pty slave) path")
|
|
root = flag.String("root", ".", "root path for configuration files")
|
|
)
|
|
|
|
flag.Parse()
|
|
|
|
var container *libcontainer.Config
|
|
f, err := os.Open(filepath.Join(*root, "container.json"))
|
|
if err != nil {
|
|
writeError(err)
|
|
}
|
|
|
|
if err := json.NewDecoder(f).Decode(&container); err != nil {
|
|
f.Close()
|
|
writeError(err)
|
|
}
|
|
f.Close()
|
|
|
|
rootfs, err := os.Getwd()
|
|
if err != nil {
|
|
writeError(err)
|
|
}
|
|
|
|
syncPipe, err := syncpipe.NewSyncPipeFromFd(0, uintptr(*pipe))
|
|
if err != nil {
|
|
writeError(err)
|
|
}
|
|
|
|
if err := namespaces.Init(container, rootfs, *console, syncPipe, flag.Args()); err != nil {
|
|
writeError(err)
|
|
}
|
|
|
|
panic("Unreachable")
|
|
}
|
|
|
|
func writeError(err error) {
|
|
fmt.Sprint(os.Stderr, err)
|
|
}
|