Skip to content

Commit 7a0302f

Browse files
committed
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 <[email protected]>
1 parent 4071c3c commit 7a0302f

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

init.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
"github.com/opencontainers/runc/libcontainer/logs"
1111
_ "github.com/opencontainers/runc/libcontainer/nsenter"
1212
"github.com/sirupsen/logrus"
13-
"github.com/urfave/cli"
1413
)
1514

1615
func init() {
1716
if len(os.Args) > 1 && os.Args[1] == "init" {
17+
// This is the golang entry point for runc init, executed
18+
// before main() but after libcontainer/nsenter's nsexec().
1819
runtime.GOMAXPROCS(1)
1920
runtime.LockOSThread()
2021

@@ -38,19 +39,13 @@ func init() {
3839
panic(fmt.Sprintf("libcontainer: failed to configure logging: %v", err))
3940
}
4041
logrus.Debug("child process in init()")
41-
}
42-
}
4342

44-
var initCommand = cli.Command{
45-
Name: "init",
46-
Usage: `initialize the namespaces and launch the process (do not call it outside of runc)`,
47-
Action: func(context *cli.Context) error {
4843
factory, _ := libcontainer.New("")
4944
if err := factory.StartInitialization(); err != nil {
5045
// as the error is sent back to the parent there is no need to log
5146
// or write it to stderr because the parent process will handle this
5247
os.Exit(1)
5348
}
5449
panic("libcontainer: container init failed to exec")
55-
},
50+
}
5651
}

main.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ func main() {
119119
deleteCommand,
120120
eventsCommand,
121121
execCommand,
122-
initCommand,
123122
killCommand,
124123
listCommand,
125124
pauseCommand,
@@ -149,10 +148,7 @@ func main() {
149148
if err := reviseRootDir(context); err != nil {
150149
return err
151150
}
152-
// let init configure logging on its own
153-
if args := context.Args(); args != nil && args.First() == "init" {
154-
return nil
155-
}
151+
156152
return logs.ConfigureLogging(createLogConfig(context))
157153
}
158154

0 commit comments

Comments
 (0)