Quellcode durchsuchen

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>
Sebastiaan van Stijn vor 2 Jahren
Ursprung
Commit
970ad4e3c7
2 geänderte Dateien mit 4 neuen und 4 gelöschten Zeilen
  1. 0 1
      daemon/container_operations_unix.go
  2. 4 3
      pkg/system/process_unix.go

+ 0 - 1
daemon/container_operations_unix.go

@@ -355,7 +355,6 @@ func killProcessDirectly(container *container.Container) error {
 	if system.IsProcessAlive(pid) {
 	if system.IsProcessAlive(pid) {
 		// Since we can not kill a zombie pid, add zombie check here
 		// Since we can not kill a zombie pid, add zombie check here
 		isZombie, err := system.IsProcessZombie(pid)
 		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 {
 		if err != nil {
 			logrus.WithError(err).WithField("container", container.ID).Warn("Container state is invalid")
 			logrus.WithError(err).WithField("container", container.ID).Warn("Container state is invalid")
 			return err
 			return err

+ 4 - 3
pkg/system/process_unix.go

@@ -29,10 +29,11 @@ func KillProcess(pid int) {
 // IsProcessZombie return true if process has a state with "Z"
 // IsProcessZombie return true if process has a state with "Z"
 // http://man7.org/linux/man-pages/man5/proc.5.html
 // http://man7.org/linux/man-pages/man5/proc.5.html
 func IsProcessZombie(pid int) (bool, error) {
 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 {
 	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
 		return false, err
 	}
 	}
 	data := string(dataBytes)
 	data := string(dataBytes)