Skip to content

Commit df2c44a

Browse files
committed
fix runc's poststart behaviour doesn't match the runtime-spec
Signed-off-by: ningmingxiao <[email protected]>
1 parent 3778ae6 commit df2c44a

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

libcontainer/container_linux.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ func (c *Container) exec() error {
236236
for {
237237
select {
238238
case result := <-blockingFifoOpenCh:
239-
return handleFifoResult(result)
239+
err := handleFifoResult(result)
240+
if err != nil {
241+
return err
242+
}
243+
return c.postStart()
240244

241245
case <-time.After(time.Millisecond * 100):
242246
stat, err := system.Stat(pid)
@@ -246,12 +250,26 @@ func (c *Container) exec() error {
246250
if err := handleFifoResult(fifoOpen(path, false)); err != nil {
247251
return errors.New("container process is already dead")
248252
}
249-
return nil
253+
return c.postStart()
250254
}
251255
}
252256
}
253257
}
254258

259+
func (c *Container) postStart() error {
260+
s, err := c.currentOCIState()
261+
if err != nil {
262+
return err
263+
}
264+
if c.config.Hooks != nil {
265+
if err := c.config.Hooks.Run(configs.Poststart, s); err != nil {
266+
logrus.Errorf("run poststart hook: %v", err)
267+
return fmt.Errorf("run poststart hook: %w", err)
268+
}
269+
}
270+
return nil
271+
}
272+
255273
func readFromExecFifo(execFifo io.Reader) error {
256274
data, err := io.ReadAll(execFifo)
257275
if err != nil {
@@ -353,19 +371,6 @@ func (c *Container) start(process *Process) (retErr error) {
353371

354372
if process.Init {
355373
c.fifo.Close()
356-
if c.config.Hooks != nil {
357-
s, err := c.currentOCIState()
358-
if err != nil {
359-
return err
360-
}
361-
362-
if err := c.config.Hooks.Run(configs.Poststart, s); err != nil {
363-
if err := ignoreTerminateErrors(parent.terminate()); err != nil {
364-
logrus.Warn(fmt.Errorf("error running poststart hook: %w", err))
365-
}
366-
return err
367-
}
368-
}
369374
}
370375
return nil
371376
}

0 commit comments

Comments
 (0)