Skip to content

Commit 4f0a7e7

Browse files
committed
libct/init: call Init from containerInit
Instead of having newContainerInit return an interface, and let its caller call Init(), it is easier to call Init directly. Do that, and rename newContainerInit to containerInit. I think it makes the code more readable and straightforward. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 72657ea commit 4f0a7e7

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

libcontainer/init_linux.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,52 +148,45 @@ func StartInitialization() (err error) {
148148
}
149149
}()
150150

151-
i, err := newContainerInit(it, pipe, consoleSocket, fifofd, logPipeFd, mountFds)
152-
if err != nil {
153-
return err
154-
}
155-
156-
// If Init succeeds, syscall.Exec will not return, hence none of the defers will be called.
157-
return i.Init()
158-
}
159-
160-
type initer interface {
161-
Init() error
151+
// If init succeeds, it will not return, hence none of the defers will be called.
152+
return containerInit(it, pipe, consoleSocket, fifofd, logPipeFd, mountFds)
162153
}
163154

164-
func newContainerInit(t initType, pipe *os.File, consoleSocket *os.File, fifoFd, logFd int, mountFds []int) (initer, error) {
155+
func containerInit(t initType, pipe *os.File, consoleSocket *os.File, fifoFd, logFd int, mountFds []int) error {
165156
var config *initConfig
166157
if err := json.NewDecoder(pipe).Decode(&config); err != nil {
167-
return nil, err
158+
return err
168159
}
169160
if err := populateProcessEnvironment(config.Env); err != nil {
170-
return nil, err
161+
return err
171162
}
172163
switch t {
173164
case initSetns:
174165
// mountFds must be nil in this case. We don't mount while doing runc exec.
175166
if mountFds != nil {
176-
return nil, errors.New("mountFds must be nil; can't mount from exec")
167+
return errors.New("mountFds must be nil; can't mount from exec")
177168
}
178169

179-
return &linuxSetnsInit{
170+
i := &linuxSetnsInit{
180171
pipe: pipe,
181172
consoleSocket: consoleSocket,
182173
config: config,
183174
logFd: logFd,
184-
}, nil
175+
}
176+
return i.Init()
185177
case initStandard:
186-
return &linuxStandardInit{
178+
i := &linuxStandardInit{
187179
pipe: pipe,
188180
consoleSocket: consoleSocket,
189181
parentPid: unix.Getppid(),
190182
config: config,
191183
fifoFd: fifoFd,
192184
logFd: logFd,
193185
mountFds: mountFds,
194-
}, nil
186+
}
187+
return i.Init()
195188
}
196-
return nil, fmt.Errorf("unknown init type %q", t)
189+
return fmt.Errorf("unknown init type %q", t)
197190
}
198191

199192
// populateProcessEnvironment loads the provided environment variables into the

0 commit comments

Comments
 (0)