github.com/dougm/docker@v1.5.0/daemon/execdriver/native/init.go (about)

     1  // +build linux
     2  
     3  package native
     4  
     5  import (
     6  	"encoding/json"
     7  	"flag"
     8  	"fmt"
     9  	"os"
    10  	"path/filepath"
    11  	"runtime"
    12  
    13  	"github.com/docker/docker/pkg/reexec"
    14  	"github.com/docker/libcontainer"
    15  	"github.com/docker/libcontainer/namespaces"
    16  )
    17  
    18  func init() {
    19  	reexec.Register(DriverName, initializer)
    20  }
    21  
    22  func initializer() {
    23  	runtime.LockOSThread()
    24  
    25  	var (
    26  		pipe    = flag.Int("pipe", 0, "sync pipe fd")
    27  		console = flag.String("console", "", "console (pty slave) path")
    28  		root    = flag.String("root", ".", "root path for configuration files")
    29  	)
    30  
    31  	flag.Parse()
    32  
    33  	var container *libcontainer.Config
    34  	f, err := os.Open(filepath.Join(*root, "container.json"))
    35  	if err != nil {
    36  		writeError(err)
    37  	}
    38  
    39  	if err := json.NewDecoder(f).Decode(&container); err != nil {
    40  		f.Close()
    41  		writeError(err)
    42  	}
    43  	f.Close()
    44  
    45  	rootfs, err := os.Getwd()
    46  	if err != nil {
    47  		writeError(err)
    48  	}
    49  
    50  	if err := namespaces.Init(container, rootfs, *console, os.NewFile(uintptr(*pipe), "child"), flag.Args()); err != nil {
    51  		writeError(err)
    52  	}
    53  
    54  	panic("Unreachable")
    55  }
    56  
    57  func writeError(err error) {
    58  	fmt.Fprint(os.Stderr, err)
    59  	os.Exit(1)
    60  }