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 17, 2024
1 parent 615068f commit 50767d7
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ func (c *linuxContainer) exec() error {
for {
select {
case result := <-blockingFifoOpenCh:
return handleFifoResult(result)
err := handleFifoResult(result)
if err != nil {
return err
}
return c.postStart()

case <-time.After(time.Millisecond * 100):
stat, err := system.Stat(pid)
Expand All @@ -280,12 +284,25 @@ func (c *linuxContainer) exec() error {
if err := handleFifoResult(fifoOpen(path, false)); err != nil {
return errors.New("container process is already dead")
}
return nil
return c.postStart()
}
}
}
}

func (c *linuxContainer) postStart() error {
s, err := c.currentOCIState()
if err != nil {
return err
}
if c.config.Hooks != nil {
if err := c.config.Hooks[configs.Poststart].RunHooks(s); err != nil {
return fmt.Errorf("run postStart hook: %w", err)
}
}
return nil
}

func readFromExecFifo(execFifo io.Reader) error {
data, err := io.ReadAll(execFifo)
if err != nil {
Expand Down Expand Up @@ -368,19 +385,6 @@ func (c *linuxContainer) 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[configs.Poststart].RunHooks(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 50767d7

Please sign in to comment.