Skip to content

Commit 3d9a118

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

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

libcontainer/container_linux.go

Lines changed: 19 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,25 @@ 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+
return fmt.Errorf("run postStart hook: %w", err)
267+
}
268+
}
269+
return nil
270+
}
271+
255272
func readFromExecFifo(execFifo io.Reader) error {
256273
data, err := io.ReadAll(execFifo)
257274
if err != nil {
@@ -353,19 +370,6 @@ func (c *Container) start(process *Process) (retErr error) {
353370

354371
if process.Init {
355372
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-
}
369373
}
370374
return nil
371375
}

0 commit comments

Comments
 (0)