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 <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-03-05 20:53:47 -08:00
parent dd6c8d76bb
commit 688ea99e1b
2 changed files with 6 additions and 2 deletions
+2 -2
View File
@@ -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)
+4
View File
@@ -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))
}