mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
ed556fb38f
We removed the syncpipe package and replaced it with specific calls to create a new *os.File from a specified fd passed to the process. This reduced code and an extra object to manage the container's init lifecycle. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
// +build linux
|
|
|
|
package native
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"github.com/docker/docker/pkg/reexec"
|
|
"github.com/docker/libcontainer"
|
|
"github.com/docker/libcontainer/namespaces"
|
|
)
|
|
|
|
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)
|
|
}
|
|
|
|
if err := namespaces.Init(container, rootfs, *console, os.NewFile(uintptr(*pipe), "child"), flag.Args()); err != nil {
|
|
writeError(err)
|
|
}
|
|
|
|
panic("Unreachable")
|
|
}
|
|
|
|
func writeError(err error) {
|
|
fmt.Fprint(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|