github.com/rentongzhang/docker@v1.8.2-rc1/daemon/execdriver/native/init.go (about)

     1  // +build linux
     2  
     3  package native
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"runtime"
     9  
    10  	"github.com/docker/docker/pkg/reexec"
    11  	"github.com/opencontainers/runc/libcontainer"
    12  )
    13  
    14  func init() {
    15  	reexec.Register(DriverName, initializer)
    16  }
    17  
    18  func fatal(err error) {
    19  	if lerr, ok := err.(libcontainer.Error); ok {
    20  		lerr.Detail(os.Stderr)
    21  		os.Exit(1)
    22  	}
    23  
    24  	fmt.Fprintln(os.Stderr, err)
    25  	os.Exit(1)
    26  }
    27  
    28  func initializer() {
    29  	runtime.GOMAXPROCS(1)
    30  	runtime.LockOSThread()
    31  	factory, err := libcontainer.New("")
    32  	if err != nil {
    33  		fatal(err)
    34  	}
    35  	if err := factory.StartInitialization(); err != nil {
    36  		fatal(err)
    37  	}
    38  
    39  	panic("unreachable")
    40  }
    41  
    42  func writeError(err error) {
    43  	fmt.Fprint(os.Stderr, err)
    44  	os.Exit(1)
    45  }