...
1 package main
2
3 import (
4 "os"
5 "runtime"
6 "strconv"
7
8 "github.com/opencontainers/runc/libcontainer"
9 _ "github.com/opencontainers/runc/libcontainer/nsenter"
10 "github.com/sirupsen/logrus"
11 )
12
13 func init() {
14 if len(os.Args) > 1 && os.Args[1] == "init" {
15
16
17 runtime.GOMAXPROCS(1)
18 runtime.LockOSThread()
19
20 level, err := strconv.Atoi(os.Getenv("_LIBCONTAINER_LOGLEVEL"))
21 if err != nil {
22 panic(err)
23 }
24
25 logPipeFd, err := strconv.Atoi(os.Getenv("_LIBCONTAINER_LOGPIPE"))
26 if err != nil {
27 panic(err)
28 }
29
30 logrus.SetLevel(logrus.Level(level))
31 logrus.SetOutput(os.NewFile(uintptr(logPipeFd), "logpipe"))
32 logrus.SetFormatter(new(logrus.JSONFormatter))
33 logrus.Debug("child process in init()")
34
35 factory, _ := libcontainer.New("")
36 if err := factory.StartInitialization(); err != nil {
37
38
39 os.Exit(1)
40 }
41 panic("libcontainer: container init failed to exec")
42 }
43 }
44
View as plain text