Skip to content

Commit 7e6e57b

Browse files
committed
fix runc's poststart behaviour doesn't match the runtime-spec
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
1 parent 615068f commit 7e6e57b

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

libcontainer/container_linux.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@ func (c *linuxContainer) exec() error {
270270
for {
271271
select {
272272
case result := <-blockingFifoOpenCh:
273-
return handleFifoResult(result)
273+
err := handleFifoResult(result)
274+
if err != nil {
275+
return err
276+
}
277+
return c.postStart()
274278

275279
case <-time.After(time.Millisecond * 100):
276280
stat, err := system.Stat(pid)
@@ -286,6 +290,19 @@ func (c *linuxContainer) exec() error {
286290
}
287291
}
288292

293+
func (c *linuxContainer) postStart() error {
294+
s, err := c.currentOCIState()
295+
if err != nil {
296+
return err
297+
}
298+
if c.config.Hooks != nil {
299+
if err := c.config.Hooks[configs.Poststart].RunHooks(s); err != nil {
300+
return fmt.Errorf("run postStart hook: %w", err)
301+
}
302+
}
303+
return nil
304+
}
305+
289306
func readFromExecFifo(execFifo io.Reader) error {
290307
data, err := io.ReadAll(execFifo)
291308
if err != nil {
@@ -368,19 +385,6 @@ func (c *linuxContainer) start(process *Process) (retErr error) {
368385

369386
if process.Init {
370387
c.fifo.Close()
371-
if c.config.Hooks != nil {
372-
s, err := c.currentOCIState()
373-
if err != nil {
374-
return err
375-
}
376-
377-
if err := c.config.Hooks[configs.Poststart].RunHooks(s); err != nil {
378-
if err := ignoreTerminateErrors(parent.terminate()); err != nil {
379-
logrus.Warn(fmt.Errorf("error running poststart hook: %w", err))
380-
}
381-
return err
382-
}
383-
}
384388
}
385389
return nil
386390
}

0 commit comments

Comments
 (0)