Skip to content

Commit

Permalink
fix runc's poststart behaviour doesn't match the runtime-spec
Browse files Browse the repository at this point in the history
Signed-off-by: ningmingxiao <[email protected]>
  • Loading branch information
ningmingxiao committed Jul 16, 2024
1 parent 3778ae6 commit c6c42bc
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,22 @@ func (c *Container) Run(process *Process) error {
// Exec signals the container to exec the users process at the end of the init.
func (c *Container) Exec() error {
c.m.Lock()
defer c.m.Unlock()
return c.exec()
err := c.exec()
if err != nil {
c.m.Unlock()
return err
}
c.m.Unlock()
s, err := c.currentOCIState()
if err != nil {
return err
}
if c.config.Hooks != nil {
if err := c.config.Hooks.Run(configs.Poststart, s); err != nil {
return fmt.Errorf("run poststart hook %w", err)
}
}
return nil
}

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

if process.Init {
c.fifo.Close()
if c.config.Hooks != nil {
s, err := c.currentOCIState()
if err != nil {
return err
}

if err := c.config.Hooks.Run(configs.Poststart, s); err != nil {
if err := ignoreTerminateErrors(parent.terminate()); err != nil {
logrus.Warn(fmt.Errorf("error running poststart hook: %w", err))
}
return err
}
}
}
return nil
}
Expand Down

0 comments on commit c6c42bc

Please sign in to comment.