From 688ea99e1b8ec8fd9491eaf48239e706ee28f563 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 5 Mar 2021 20:53:47 -0800 Subject: [PATCH] runc init: fix double call to ConfigureLogs I have noticed that ConfigureLogs do not return an error in case logging was already configured -- instead it just warns about it. So I went ahead and changed the warning to the actual error... ... only to discover I broke things badly, because in case of runc init logging is configured twice. The fix is to not configure logging in case we are init. Signed-off-by: Kir Kolyshkin --- libcontainer/logs/logs.go | 4 ++-- main.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libcontainer/logs/logs.go b/libcontainer/logs/logs.go index 3a45f1a5f..f75084161 100644 --- a/libcontainer/logs/logs.go +++ b/libcontainer/logs/logs.go @@ -8,6 +8,7 @@ import ( "os" "sync" + "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -64,8 +65,7 @@ func ConfigureLogging(config Config) error { defer configureMutex.Unlock() if loggingConfigured { - logrus.Debug("logging has already been configured") - return nil + return errors.New("logging has already been configured") } logrus.SetLevel(config.LogLevel) diff --git a/main.go b/main.go index 5efecb9a7..97bce5bf5 100644 --- a/main.go +++ b/main.go @@ -150,6 +150,10 @@ func main() { if err := reviseRootDir(context); err != nil { return err } + // let init configure logging on its own + if args := context.Args(); args != nil && args.First() == "init" { + return nil + } return logs.ConfigureLogging(createLogConfig(context)) }