From 7a0302f0d79e32766e28647cfae0fba70e6f9dea Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sun, 25 Jul 2021 19:20:42 -0700 Subject: [PATCH] runc init: simplify runc init is special. For one thing, it needs to do a few things before main(), so we have func init() that checks if we're init and does that. What happens next is main() is called, which does some options parsing, figures out it needs to call initCommand.Action and so it does. Now, main() is entirely unnecessary -- we can do everything right from init(). Hopefully the change makes things slightly less complicated. From a user's perspective, the only change is runc help no longer lists 'runc init` (which I think it also good). Signed-off-by: Kir Kolyshkin --- init.go | 11 +++-------- main.go | 6 +----- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/init.go b/init.go index 59ce1e8c7..d39492952 100644 --- a/init.go +++ b/init.go @@ -10,11 +10,12 @@ import ( "github.com/opencontainers/runc/libcontainer/logs" _ "github.com/opencontainers/runc/libcontainer/nsenter" "github.com/sirupsen/logrus" - "github.com/urfave/cli" ) func init() { if len(os.Args) > 1 && os.Args[1] == "init" { + // This is the golang entry point for runc init, executed + // before main() but after libcontainer/nsenter's nsexec(). runtime.GOMAXPROCS(1) runtime.LockOSThread() @@ -38,13 +39,7 @@ func init() { panic(fmt.Sprintf("libcontainer: failed to configure logging: %v", err)) } logrus.Debug("child process in init()") - } -} -var initCommand = cli.Command{ - Name: "init", - Usage: `initialize the namespaces and launch the process (do not call it outside of runc)`, - Action: func(context *cli.Context) error { factory, _ := libcontainer.New("") if err := factory.StartInitialization(); err != nil { // as the error is sent back to the parent there is no need to log @@ -52,5 +47,5 @@ var initCommand = cli.Command{ os.Exit(1) } panic("libcontainer: container init failed to exec") - }, + } } diff --git a/main.go b/main.go index 45652ab32..f141e79b4 100644 --- a/main.go +++ b/main.go @@ -119,7 +119,6 @@ func main() { deleteCommand, eventsCommand, execCommand, - initCommand, killCommand, listCommand, pauseCommand, @@ -149,10 +148,7 @@ 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)) }