From 317b853a0d70bab56d2c0f814e6d1c4203a48c5f Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Thu, 16 Jan 2025 01:16:42 +1400
Subject: [PATCH 189/198] add sandbox pid init and verify sandbox ready when
 create container

Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
 src/daemon/entry/cri/v1/v1_cri_container_manager_service.cc | 6 ++++++
 src/daemon/sandbox/sandbox.cc                               | 1 +
 2 files changed, 7 insertions(+)

diff --git a/src/daemon/entry/cri/v1/v1_cri_container_manager_service.cc b/src/daemon/entry/cri/v1/v1_cri_container_manager_service.cc
index e8dcd699..abf60c0c 100644
--- a/src/daemon/entry/cri/v1/v1_cri_container_manager_service.cc
+++ b/src/daemon/entry/cri/v1/v1_cri_container_manager_service.cc
@@ -483,6 +483,12 @@ std::string ContainerManagerService::CreateContainer(const std::string &podSandb
         return response_id;
     }
 
+    // verify whether the sandbox is ready
+    if (!sandbox->IsReady()) {
+        error.Errorf("Failed to generate sandbox_info because the sandbox %s is not ready", sandbox->GetId().c_str());
+        return nullptr;
+    }
+
 #ifdef ENABLE_NRI
     Errors nriErr;
     nri_container_adjustment *adjust = NULL;
diff --git a/src/daemon/sandbox/sandbox.cc b/src/daemon/sandbox/sandbox.cc
index e2f42237..b97c0bc6 100644
--- a/src/daemon/sandbox/sandbox.cc
+++ b/src/daemon/sandbox/sandbox.cc
@@ -100,6 +100,7 @@ Sandbox::Sandbox(const std::string id, const std::string &rootdir, const std::st
     const uint64_t defaultCreatedAt { 1 };
     m_state.createdAt = defaultCreatedAt;
     m_image = image;
+    m_state.pid = -1;
 }
 
 auto Sandbox::IsReady() -> bool
-- 
2.34.1

