mirror of
https://github.com/containers/podman
synced 2024-10-19 00:34:18 +00:00
Properly parse stderr when updating container status
I believe the previous code meant to use cmd.Run instead of cmd.Start. The issue is that cmd.Start returns before the command has finished executing, so the conditional body checking for the stderr of the command never gets executed. Raise the cmd.Start up into it's own conditional, which is checking for whether the process could be started. Then we consume stderr, check for some specific strings in the output, and then finally continue on with the rest of the code. Signed-off-by: Keith Johnson <kj@ubergeek42.com>
This commit is contained in:
parent
2aad385b51
commit
83671f95d8
|
@ -232,29 +232,31 @@ func (r *ConmonOCIRuntime) UpdateContainerStatus(ctr *Container) error {
|
|||
return fmt.Errorf("getting stderr pipe: %w", err)
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
out, err2 := io.ReadAll(errPipe)
|
||||
if err2 != nil {
|
||||
return fmt.Errorf("getting container %s state: %w", ctr.ID(), err)
|
||||
}
|
||||
if strings.Contains(string(out), "does not exist") || strings.Contains(string(out), "No such file") {
|
||||
if err := ctr.removeConmonFiles(); err != nil {
|
||||
logrus.Debugf("unable to remove conmon files for container %s", ctr.ID())
|
||||
}
|
||||
ctr.state.ExitCode = -1
|
||||
ctr.state.FinishedTime = time.Now()
|
||||
ctr.state.State = define.ContainerStateExited
|
||||
return ctr.runtime.state.AddContainerExitCode(ctr.ID(), ctr.state.ExitCode)
|
||||
}
|
||||
return fmt.Errorf("getting container %s state. stderr/out: %s: %w", ctr.ID(), out, err)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error launching container runtime: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = cmd.Wait()
|
||||
}()
|
||||
|
||||
stderr, err := io.ReadAll(errPipe)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading stderr: %s: %w", ctr.ID(), err)
|
||||
}
|
||||
if strings.Contains(string(stderr), "does not exist") || strings.Contains(string(stderr), "No such file") {
|
||||
if err := ctr.removeConmonFiles(); err != nil {
|
||||
logrus.Debugf("unable to remove conmon files for container %s", ctr.ID())
|
||||
}
|
||||
ctr.state.ExitCode = -1
|
||||
ctr.state.FinishedTime = time.Now()
|
||||
ctr.state.State = define.ContainerStateExited
|
||||
return ctr.runtime.state.AddContainerExitCode(ctr.ID(), ctr.state.ExitCode)
|
||||
}
|
||||
if err := errPipe.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out, err := io.ReadAll(outPipe)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading stdout: %s: %w", ctr.ID(), err)
|
||||
|
|
Loading…
Reference in a new issue