Skip to content

Commit 58731e3

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

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
@@ -237,7 +237,11 @@ func (c *Container) exec() error {
237237
for {
238238
select {
239239
case result := <-blockingFifoOpenCh:
240-
return handleFifoResult(result)
240+
err := handleFifoResult(result)
241+
if err != nil {
242+
return err
243+
}
244+
return c.postStart()
241245

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

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

372390
if process.Init {
373391
c.fifo.Close()
374-
if c.config.HasHook(configs.Poststart) {
375-
s, err := c.currentOCIState()
376-
if err != nil {
377-
return err
378-
}
379-
380-
if err := c.config.Hooks.Run(configs.Poststart, s); err != nil {
381-
if err := ignoreTerminateErrors(parent.terminate()); err != nil {
382-
logrus.Warn(fmt.Errorf("error running poststart hook: %w", err))
383-
}
384-
return err
385-
}
386-
}
387392
}
388393
return nil
389394
}

0 commit comments

Comments
 (0)