Blame SOURCES/69518f0bbdb1f11113f46a4d794e09e2f21f5e91.patch

a7f575
From 69518f0bbdb1f11113f46a4d794e09e2f21f5e91 Mon Sep 17 00:00:00 2001
a7f575
From: Ulrich Obergfell <uobergfe@redhat.com>
a7f575
Date: Thu, 10 Oct 2019 11:59:44 +0200
a7f575
Subject: [PATCH] fix error handling in restore() function  -  version 2
a7f575
a7f575
If runtime.Load() returns an error, the restore() function removes the
a7f575
/run/docker/libcontainerd/containerd/CONTAINERID directory recursively.
a7f575
However, this is wrong if the error is not related to the init process
a7f575
of the container.
a7f575
a7f575
This patch introduces the following changes to the runtime.Load() function:
a7f575
a7f575
- runtime.Load() handles errors from readProcessState() autonomously. The
a7f575
  /run/docker/libcontainerd/containerd/CONTAINERID/PROCESSID directory will
a7f575
  be removed recursively, and a warning message will be logged.
a7f575
a7f575
- Errors returned by runtime.Load() are always related to the init process,
a7f575
  so restore() may remove /run/docker/libcontainerd/containerd/CONTAINERID.
a7f575
a7f575
Signed-off-by: Ulrich Obergfell <uobergfe@redhat.com>
a7f575
---
a7f575
 runtime/container.go | 9 ++++++---
a7f575
 1 file changed, 6 insertions(+), 3 deletions(-)
a7f575
a7f575
diff --git a/runtime/container.go b/runtime/container.go
a7f575
index 2e9e663..489e407 100644
a7f575
--- a/runtime/container.go
a7f575
+++ b/runtime/container.go
a7f575
@@ -182,11 +182,14 @@ func Load(root, id, shimName string, timeout time.Duration) (Container, error) {
a7f575
 			continue
a7f575
 		}
a7f575
 		pid := d.Name()
a7f575
-		s, err := readProcessState(filepath.Join(root, id, pid))
a7f575
+		processStateDir := filepath.Join(root, id, pid)
a7f575
+		s, err := readProcessState(processStateDir)
a7f575
 		if err != nil {
a7f575
-			return nil, err
a7f575
+			logrus.WithFields(logrus.Fields{"error": err, "pid": pid}).Warnf("containerd: failed to load exec process,removing state directory.")
a7f575
+			os.RemoveAll(processStateDir)
a7f575
+			continue
a7f575
 		}
a7f575
-		p, err := loadProcess(filepath.Join(root, id, pid), pid, c, s)
a7f575
+		p, err := loadProcess(processStateDir, pid, c, s)
a7f575
 		if err != nil {
a7f575
 			logrus.WithField("id", id).WithField("pid", pid).Debugf("containerd: error loading process %s", err)
a7f575
 			continue