예제 #1
0
파일: driver.go 프로젝트: hwpaas/docker
func init() {
	execdriver.RegisterInitFunc(DriverName, func(args *execdriver.InitArgs) error {
		var container *libcontainer.Config
		f, err := os.Open(filepath.Join(args.Root, "container.json"))
		if err != nil {
			return err
		}

		if err := json.NewDecoder(f).Decode(&container); err != nil {
			f.Close()
			return err
		}
		f.Close()

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

		syncPipe, err := syncpipe.NewSyncPipeFromFd(0, uintptr(args.Pipe))
		if err != nil {
			return err
		}

		if err := namespaces.Init(container, rootfs, args.Console, syncPipe, args.Args); err != nil {
			return err
		}

		return nil
	})
}
예제 #2
0
파일: init.go 프로젝트: NERSC/docker
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")
}
예제 #3
0
파일: init.go 프로젝트: BreezeWu/docker
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)
	}
}
예제 #4
0
// init runs the libcontainer initialization code because of the busybox style needs
// to work around the go runtime and the issues with forking
func init() {
	if len(os.Args) < 2 || os.Args[1] != "init" {
		return
	}
	runtime.LockOSThread()

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

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

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

	if err := namespaces.Init(container, rootfs, "", syncPipe, os.Args[3:]); err != nil {
		log.Fatalf("unable to initialize for container: %s", err)
	}
	os.Exit(1)
}
예제 #5
0
// init runs the libcontainer initialization code because of the busybox style needs
// to work around the go runtime and the issues with forking
func init() {
	if len(os.Args) < 2 {
		return
	}
	// handle init
	if len(os.Args) >= 2 && os.Args[1] == "init" {
		runtime.LockOSThread()

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

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

		if err := namespaces.Init(container, rootfs, "", os.NewFile(3, "pipe"), os.Args[3:]); err != nil {
			log.Fatalf("unable to initialize for container: %s", err)
		}
		os.Exit(1)
	}

	// handle execin
	if len(os.Args) >= 2 && os.Args[0] == "nsenter-exec" {
		runtime.LockOSThread()

		// User args are passed after '--' in the command line.
		userArgs := findUserArgs()

		config, err := loadConfigFromFd()
		if err != nil {
			log.Fatalf("docker-exec: unable to receive config from sync pipe: %s", err)
		}

		if err := namespaces.FinalizeSetns(config, userArgs); err != nil {
			log.Fatalf("docker-exec: failed to exec: %s", err)
		}
		os.Exit(1)
	}
}
예제 #6
0
파일: init_test.go 프로젝트: NERSC/docker
// init runs the libcontainer initialization code because of the busybox style needs
// to work around the go runtime and the issues with forking
func init() {
	if len(os.Args) < 2 || os.Args[1] != "init" {
		return
	}
	runtime.LockOSThread()

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

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

	if err := namespaces.Init(container, rootfs, "", os.NewFile(3, "pipe"), os.Args[3:]); err != nil {
		log.Fatalf("unable to initialize for container: %s", err)
	}
	os.Exit(1)
}