mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
runc init: pass _LIBCONTAINER_LOGLEVEL as int
Instead of passing _LIBCONTAINER_LOGLEVEL as a string (like "debug" or "info"), use a numeric value. Also, simplify the init log level passing code -- since we actually use the same level as the runc binary, just get it from logrus. This is a preparation for the next commit. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -132,11 +132,6 @@ func execProcess(context *cli.Context) (int, error) {
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
logLevel := "info"
|
|
||||||
if context.GlobalBool("debug") {
|
|
||||||
logLevel = "debug"
|
|
||||||
}
|
|
||||||
|
|
||||||
r := &runner{
|
r := &runner{
|
||||||
enableSubreaper: false,
|
enableSubreaper: false,
|
||||||
shouldDestroy: false,
|
shouldDestroy: false,
|
||||||
@@ -147,7 +142,6 @@ func execProcess(context *cli.Context) (int, error) {
|
|||||||
action: CT_ACT_RUN,
|
action: CT_ACT_RUN,
|
||||||
init: false,
|
init: false,
|
||||||
preserveFDs: context.Int("preserve-fds"),
|
preserveFDs: context.Int("preserve-fds"),
|
||||||
logLevel: logLevel,
|
|
||||||
}
|
}
|
||||||
return r.run(p)
|
return r.run(p)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func init() {
|
|||||||
runtime.GOMAXPROCS(1)
|
runtime.GOMAXPROCS(1)
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
|
|
||||||
logLevel, err := logrus.ParseLevel(os.Getenv("_LIBCONTAINER_LOGLEVEL"))
|
level, err := strconv.Atoi(os.Getenv("_LIBCONTAINER_LOGLEVEL"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ func init() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.SetLevel(logLevel)
|
logrus.SetLevel(logrus.Level(level))
|
||||||
logrus.SetOutput(os.NewFile(uintptr(logPipeFd), "logpipe"))
|
logrus.SetOutput(os.NewFile(uintptr(logPipeFd), "logpipe"))
|
||||||
logrus.SetFormatter(new(logrus.JSONFormatter))
|
logrus.SetFormatter(new(logrus.JSONFormatter))
|
||||||
logrus.Debug("child process in init()")
|
logrus.Debug("child process in init()")
|
||||||
|
|||||||
+1
-8
@@ -255,7 +255,6 @@ type runner struct {
|
|||||||
action CtAct
|
action CtAct
|
||||||
notifySocket *notifySocket
|
notifySocket *notifySocket
|
||||||
criuOpts *libcontainer.CriuOpts
|
criuOpts *libcontainer.CriuOpts
|
||||||
logLevel string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *runner) run(config *specs.Process) (int, error) {
|
func (r *runner) run(config *specs.Process) (int, error) {
|
||||||
@@ -272,9 +271,9 @@ func (r *runner) run(config *specs.Process) (int, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
process.LogLevel = strconv.Itoa(int(logrus.GetLevel()))
|
||||||
// Populate the fields that come from runner.
|
// Populate the fields that come from runner.
|
||||||
process.Init = r.init
|
process.Init = r.init
|
||||||
process.LogLevel = r.logLevel
|
|
||||||
if len(r.listenFDs) > 0 {
|
if len(r.listenFDs) > 0 {
|
||||||
process.Env = append(process.Env, "LISTEN_FDS="+strconv.Itoa(len(r.listenFDs)), "LISTEN_PID=1")
|
process.Env = append(process.Env, "LISTEN_FDS="+strconv.Itoa(len(r.listenFDs)), "LISTEN_PID=1")
|
||||||
process.ExtraFiles = append(process.ExtraFiles, r.listenFDs...)
|
process.ExtraFiles = append(process.ExtraFiles, r.listenFDs...)
|
||||||
@@ -431,11 +430,6 @@ func startContainer(context *cli.Context, spec *specs.Spec, action CtAct, criuOp
|
|||||||
listenFDs = activation.Files(false)
|
listenFDs = activation.Files(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
logLevel := "info"
|
|
||||||
if context.GlobalBool("debug") {
|
|
||||||
logLevel = "debug"
|
|
||||||
}
|
|
||||||
|
|
||||||
r := &runner{
|
r := &runner{
|
||||||
enableSubreaper: !context.Bool("no-subreaper"),
|
enableSubreaper: !context.Bool("no-subreaper"),
|
||||||
shouldDestroy: !context.Bool("keep"),
|
shouldDestroy: !context.Bool("keep"),
|
||||||
@@ -449,7 +443,6 @@ func startContainer(context *cli.Context, spec *specs.Spec, action CtAct, criuOp
|
|||||||
action: action,
|
action: action,
|
||||||
criuOpts: criuOpts,
|
criuOpts: criuOpts,
|
||||||
init: true,
|
init: true,
|
||||||
logLevel: logLevel,
|
|
||||||
}
|
}
|
||||||
return r.run(spec.Process)
|
return r.run(spec.Process)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user