Skip to content

Commit

Permalink
Merge pull request containers#16504 from giuseppe/add-check-for-ESRCH
Browse files Browse the repository at this point in the history
libpod: treat ESRCH from /proc/PID/cgroup as ENOENT
  • Loading branch information
openshift-merge-robot authored Nov 15, 2022
2 parents ee1c921 + 36f8dfa commit 0253d3c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package libpod

import (
"bytes"
"errors"
"fmt"
"io"
"net"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/containers/storage"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

// CgroupfsDefaultCgroupParent is the cgroup parent for CgroupFS in libpod
Expand Down Expand Up @@ -1009,8 +1011,9 @@ func (c *Container) cGroupPath() (string, error) {
lines, err := os.ReadFile(procPath)
if err != nil {
// If the file doesn't exist, it means the container could have been terminated
// so report it.
if os.IsNotExist(err) {
// so report it. Also check for ESRCH, which means the container could have been
// terminated after the file under /proc was opened but before it was read.
if errors.Is(err, os.ErrNotExist) || errors.Is(err, unix.ESRCH) {
return "", fmt.Errorf("cannot get cgroup path unless container %s is running: %w", c.ID(), define.ErrCtrStopped)
}
return "", err
Expand Down

0 comments on commit 0253d3c

Please sign in to comment.