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 b766494
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,46 @@ func (c *Container) Start(process *Process) error {
// after start returns but opens the fifo after start returns.
func (c *Container) Run(process *Process) error {
c.m.Lock()
defer c.m.Unlock()
if err := c.start(process); err != nil {
c.m.Unlock()
return err
}
if process.Init {
return c.exec()
err := c.exec()
if err != nil {
c.m.Unlock()
return err
}
c.m.Unlock()
return c.PostStart()
}
c.m.Unlock()
return nil
}

func (c *Container) PostStart() error {
s, err := c.OCIState()
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
}

// 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()
return c.PostStart()
}

func (c *Container) exec() error {
Expand Down Expand Up @@ -353,19 +378,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 b766494

Please sign in to comment.