Esempio n. 1
0
func initAction(context *cli.Context) {
	runtime.LockOSThread()

	container, err := loadConfig()
	if err != nil {
		log.Fatal(err)
	}

	rootfs, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}

	pipeFd, err := strconv.Atoi(rawPipeFd)
	if err != nil {
		log.Fatal(err)
	}

	syncPipe, err := syncpipe.NewSyncPipeFromFd(0, uintptr(pipeFd))
	if err != nil {
		log.Fatalf("unable to create sync pipe: %s", err)
	}

	if err := namespaces.Init(container, rootfs, console, syncPipe, []string(context.Args())); err != nil {
		log.Fatalf("unable to initialize for container: %s", err)
	}
}
Esempio n. 2
0
// loadConfigFromFd loads a container's config from the sync pipe that is provided by
// fd 3 when running a process
func loadConfigFromFd() (*libcontainer.Config, error) {
	syncPipe, err := syncpipe.NewSyncPipeFromFd(0, 3)
	if err != nil {
		return nil, err
	}

	var config *libcontainer.Config
	if err := syncPipe.ReadFromParent(&config); err != nil {
		return nil, err
	}

	return config, nil
}
Esempio n. 3
0
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")
}