Skip to content

Commit c6c42bc

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

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

libcontainer/container_linux.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,22 @@ func (c *Container) Run(process *Process) error {
225225
// Exec signals the container to exec the users process at the end of the init.
226226
func (c *Container) Exec() error {
227227
c.m.Lock()
228-
defer c.m.Unlock()
229-
return c.exec()
228+
err := c.exec()
229+
if err != nil {
230+
c.m.Unlock()
231+
return err
232+
}
233+
c.m.Unlock()
234+
s, err := c.currentOCIState()
235+
if err != nil {
236+
return err
237+
}
238+
if c.config.Hooks != nil {
239+
if err := c.config.Hooks.Run(configs.Poststart, s); err != nil {
240+
return fmt.Errorf("run poststart hook %w", err)
241+
}
242+
}
243+
return nil
230244
}
231245

232246
func (c *Container) exec() error {
@@ -353,19 +367,6 @@ func (c *Container) start(process *Process) (retErr error) {
353367

354368
if process.Init {
355369
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-
}
369370
}
370371
return nil
371372
}

0 commit comments

Comments
 (0)