init.go 1004 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "log"
  4. "os"
  5. "runtime"
  6. "strconv"
  7. "github.com/codegangsta/cli"
  8. "github.com/docker/libcontainer/namespaces"
  9. "github.com/docker/libcontainer/syncpipe"
  10. )
  11. var (
  12. dataPath = os.Getenv("data_path")
  13. console = os.Getenv("console")
  14. rawPipeFd = os.Getenv("pipe")
  15. initCommand = cli.Command{
  16. Name: "init",
  17. Usage: "runs the init process inside the namespace",
  18. Action: initAction,
  19. }
  20. )
  21. func initAction(context *cli.Context) {
  22. runtime.LockOSThread()
  23. container, err := loadConfig()
  24. if err != nil {
  25. log.Fatal(err)
  26. }
  27. rootfs, err := os.Getwd()
  28. if err != nil {
  29. log.Fatal(err)
  30. }
  31. pipeFd, err := strconv.Atoi(rawPipeFd)
  32. if err != nil {
  33. log.Fatal(err)
  34. }
  35. syncPipe, err := syncpipe.NewSyncPipeFromFd(0, uintptr(pipeFd))
  36. if err != nil {
  37. log.Fatalf("unable to create sync pipe: %s", err)
  38. }
  39. if err := namespaces.Init(container, rootfs, console, syncPipe, []string(context.Args())); err != nil {
  40. log.Fatalf("unable to initialize for container: %s", err)
  41. }
  42. }