mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-01 04:08:05 +00:00
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 <kolyshkin@gmail.com>
This commit is contained in:
11
init.go
11
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")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
6
main.go
6
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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user