pkg/system: IsProcessZombie() ignore "os.ErrNotExist" errors

If the file doesn't exist, the process isn't running, so we should be able
to ignore that.

Also remove an intermediate variable.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-10-15 14:50:48 +02:00
parent 8d6da1e100
commit 970ad4e3c7
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 4 additions and 4 deletions

View file

@ -355,7 +355,6 @@ func killProcessDirectly(container *container.Container) error {
if system.IsProcessAlive(pid) {
// Since we can not kill a zombie pid, add zombie check here
isZombie, err := system.IsProcessZombie(pid)
// TODO(thaJeztah) should we ignore os.IsNotExist() here? ("/proc/<pid>/stat" will be gone if the process exited)
if err != nil {
logrus.WithError(err).WithField("container", container.ID).Warn("Container state is invalid")
return err

View file

@ -29,10 +29,11 @@ func KillProcess(pid int) {
// IsProcessZombie return true if process has a state with "Z"
// http://man7.org/linux/man-pages/man5/proc.5.html
func IsProcessZombie(pid int) (bool, error) {
statPath := fmt.Sprintf("/proc/%d/stat", pid)
dataBytes, err := os.ReadFile(statPath)
dataBytes, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", pid))
if err != nil {
// TODO(thaJeztah) should we ignore os.IsNotExist() here? ("/proc/<pid>/stat" will be gone if the process exited)
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
data := string(dataBytes)