diff options
Diffstat (limited to 'container/init.go')
| -rw-r--r-- | container/init.go | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/container/init.go b/container/init.go index 41de58cd..510d9f59 100644 --- a/container/init.go +++ b/container/init.go @@ -2,6 +2,7 @@ package container import ( "context" + "encoding/gob" "errors" "fmt" "log" @@ -130,7 +131,7 @@ type initParams struct { Verbose bool } -// Init is called by [TryArgv0] if the current process is the container init. +// Init is called if the current process is the container init. func Init(msg message.Msg) { initEntrypoint(direct{}, msg) } func initEntrypoint(k syscallDispatcher, msg message.Msg) { @@ -642,18 +643,37 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) { // initName is the prefix used by log.std in the init process. const initName = "init" -// TryArgv0 calls [Init] if the last element of argv0 is "init". -// If a nil msg is passed, the system logger is used instead. -func TryArgv0(msg message.Msg) { - if msg == nil { +var _ = func() struct{} { + for _, v := range []any{ + (*AutoEtcOp)(nil), + (*AutoRootOp)(nil), + (*BindMountOp)(nil), + (*DaemonOp)(nil), + (*MkdirOp)(nil), + (*MountDevOp)(nil), + (*MountOverlayOp)(nil), + (*MountProcOp)(nil), + (*MountTmpfsOp)(nil), + (*RemountOp)(nil), + (*SymlinkOp)(nil), + (*TmpfileOp)(nil), + } { + gob.Register(v) + } + + if len(os.Args) == 1 && filepath.Base(os.Args[0]) == initName { log.SetPrefix(initName + ": ") log.SetFlags(0) - msg = message.New(log.Default()) - } + msg := message.New(log.Default()) - if len(os.Args) > 0 && filepath.Base(os.Args[0]) == initName { Init(msg) msg.BeforeExit() os.Exit(0) } -} + return struct{}{} +}() + +// TryArgv0 is a noop. +// +// Deprecated: init is now implemented as an import side effect. +func TryArgv0(_ message.Msg) {} |
