1 Star 0 Fork 43

zhongtao/src-iSulad

forked from src-openEuler/iSulad 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0004-do-not-cleanup-if-the-directory-does-not-exist.patch 2.68 KB
一键复制 编辑 原始数据 按行查看 历史
jake 提交于 2024-04-02 11:50 . upgrade from upstream
From 7f13d95572040d30b70edbfac3c4b7350ee8855c Mon Sep 17 00:00:00 2001
From: zhongtao <[email protected]>
Date: Fri, 26 Jan 2024 12:59:45 +0800
Subject: [PATCH 04/43] do not cleanup if the directory does not exist
Signed-off-by: zhongtao <[email protected]>
---
src/cmd/isulad/main.c | 20 ++++++++++++++++++-
.../container/leftover_cleanup/cleanup.c | 13 +++++++++++-
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c
index deca72be..fd0b6e89 100644
--- a/src/cmd/isulad/main.c
+++ b/src/cmd/isulad/main.c
@@ -1270,8 +1270,26 @@ static int do_ensure_isulad_tmpdir_security(const char *isulad_tmp_dir)
int nret;
char tmp_dir[PATH_MAX] = { 0 };
char cleanpath[PATH_MAX] = { 0 };
+ char isulad_tmp_cleanpath[PATH_MAX] = { 0 };
- if (realpath(isulad_tmp_dir, cleanpath) == NULL) {
+ if (util_clean_path(isulad_tmp_dir, isulad_tmp_cleanpath, sizeof(isulad_tmp_cleanpath)) == NULL) {
+ ERROR("Failed to clean path for %s", isulad_tmp_dir);
+ return -1;
+ }
+
+ // Determine whether isulad_tmp_dir exists. If it does not exist, create it
+ // to prevent realpath from reporting errors because the folder does not exist.
+ if (!util_dir_exists(isulad_tmp_cleanpath)) {
+ nret = snprintf(tmp_dir, PATH_MAX, "%s/isulad_tmpdir", isulad_tmp_cleanpath);
+ if (nret < 0 || (size_t)nret >= PATH_MAX) {
+ ERROR("Failed to snprintf");
+ return -1;
+ }
+ INFO("iSulad tmpdir: %s does not exist, create it", isulad_tmp_dir);
+ return recreate_tmpdir(tmp_dir);
+ }
+
+ if (realpath(isulad_tmp_cleanpath, cleanpath) == NULL) {
ERROR("Failed to get real path for %s", tmp_dir);
return -1;
}
diff --git a/src/daemon/modules/container/leftover_cleanup/cleanup.c b/src/daemon/modules/container/leftover_cleanup/cleanup.c
index 08151f42..16dba630 100644
--- a/src/daemon/modules/container/leftover_cleanup/cleanup.c
+++ b/src/daemon/modules/container/leftover_cleanup/cleanup.c
@@ -174,8 +174,19 @@ static void cleanup_path(char *dir)
int nret;
char tmp_dir[PATH_MAX] = { 0 };
char cleanpath[PATH_MAX] = { 0 };
+ char dir_cleanpath[PATH_MAX] = { 0 };
- if (realpath(dir, cleanpath) == NULL) {
+ if (util_clean_path(dir, dir_cleanpath, sizeof(dir_cleanpath)) == NULL) {
+ ERROR("clean path for %s failed", dir);
+ return;
+ }
+
+ // If dir does not exist, skip cleanup
+ if (!util_dir_exists(dir_cleanpath)) {
+ return;
+ }
+
+ if (realpath(dir_cleanpath, cleanpath) == NULL) {
ERROR("get real path for %s failed", tmp_dir);
return;
}
--
2.34.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/taotao-sauce/src-iSulad.git
[email protected]:taotao-sauce/src-iSulad.git
taotao-sauce
src-iSulad
src-iSulad
master

搜索帮助