From 602675912f09a37c71c376dd16904f85e10c5338 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Wed, 6 Sep 2023 10:45:37 +0800
Subject: [PATCH 139/145] do not report low level error to user

Signed-off-by: haozi007 <liuhao27@huawei.com>
---
 .../cri/cri_container_manager_service_impl.cc   |  3 ++-
 src/daemon/entry/cri/cri_helpers.cc             |  4 ++--
 src/daemon/entry/cri/naming.cc                  |  3 ++-
 src/daemon/executor/container_cb/execution.c    |  4 ++--
 .../executor/container_cb/execution_network.c   | 17 ++++++++---------
 .../executor/container_cb/execution_stream.c    |  4 ++--
 src/daemon/modules/container/container_unix.c   |  2 +-
 src/daemon/modules/image/external/ext_image.c   |  4 ++--
 src/daemon/modules/image/oci/oci_load.c         |  2 +-
 .../modules/runtime/engines/lcr/lcr_rt_ops.c    |  3 +--
 src/daemon/modules/service/service_container.c  |  2 +-
 src/daemon/modules/spec/verify.c                |  2 +-
 src/daemon/modules/volume/local.c               |  8 ++++----
 src/utils/tar/isulad_tar.c                      | 16 ++++++++--------
 src/utils/tar/util_archive.c                    | 12 ++++++------
 15 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/src/daemon/entry/cri/cri_container_manager_service_impl.cc b/src/daemon/entry/cri/cri_container_manager_service_impl.cc
index c358c934..743c7159 100644
--- a/src/daemon/entry/cri/cri_container_manager_service_impl.cc
+++ b/src/daemon/entry/cri/cri_container_manager_service_impl.cc
@@ -543,8 +543,9 @@ void ContainerManagerServiceImpl::CreateContainerLogSymlink(const std::string &c
             WARN("Deleted previously existing symlink file: %s", path);
         }
         if (symlink(realPath, path) != 0) {
+            SYSERROR("failed to create symbolic link %s to the container log file %s for container %s", path, realPath, containerID.c_str());
             error.Errorf("failed to create symbolic link %s to the container log file %s for container %s: %s", path,
-                         realPath, containerID.c_str(), strerror(errno));
+                         realPath, containerID.c_str());
             goto cleanup;
         }
     } else {
diff --git a/src/daemon/entry/cri/cri_helpers.cc b/src/daemon/entry/cri/cri_helpers.cc
index e2d00bc7..276fe9dd 100644
--- a/src/daemon/entry/cri/cri_helpers.cc
+++ b/src/daemon/entry/cri/cri_helpers.cc
@@ -916,8 +916,8 @@ void RemoveContainerLogSymlink(const std::string &containerID, Errors &error)
     if (path != nullptr) {
         // Only remove the symlink when container log path is specified.
         if (util_path_remove(path) != 0 && errno != ENOENT) {
-            error.Errorf("Failed to remove container %s log symlink %s: %s", containerID.c_str(), path,
-                         strerror(errno));
+            SYSERROR("Failed to remove container %s log symlink %s.", containerID.c_str(), path);
+            error.Errorf("Failed to remove container %s log symlink %s.", containerID.c_str(), path);
             goto cleanup;
         }
     }
diff --git a/src/daemon/entry/cri/naming.cc b/src/daemon/entry/cri/naming.cc
index 1526f044..ce4c4359 100644
--- a/src/daemon/entry/cri/naming.cc
+++ b/src/daemon/entry/cri/naming.cc
@@ -46,7 +46,8 @@ static int parseName(const std::string &name, std::vector<std::string> &items, u
     }
 
     if (util_safe_uint(items[5].c_str(), &attempt)) {
-        err.Errorf("failed to parse the sandbox name %s: %s", name.c_str(), strerror(errno));
+        SYSERROR("failed to parse the sandbox name %s.", name.c_str());
+        err.Errorf("failed to parse the sandbox name %s.", name.c_str());
         return -1;
     }
 
diff --git a/src/daemon/executor/container_cb/execution.c b/src/daemon/executor/container_cb/execution.c
index c5f7a853..9aa8b334 100644
--- a/src/daemon/executor/container_cb/execution.c
+++ b/src/daemon/executor/container_cb/execution.c
@@ -339,13 +339,13 @@ static int maybe_create_cpu_realtime_file(int64_t value, const char *file, const
     fd = util_open(fpath, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0700);
     if (fd < 0) {
         SYSERROR("Failed to open file: %s.", fpath);
-        isulad_set_error_message("Failed to open file: %s: %s", fpath, strerror(errno));
+        isulad_set_error_message("Failed to open file: %s.", fpath);
         return -1;
     }
     nwrite = util_write_nointr(fd, buf, strlen(buf));
     if (nwrite < 0 || (size_t)nwrite != strlen(buf)) {
         SYSERROR("Failed to write %s to %s.", buf, fpath);
-        isulad_set_error_message("Failed to write '%s' to '%s': %s", buf, fpath, strerror(errno));
+        isulad_set_error_message("Failed to write '%s' to '%s'.", buf, fpath);
         close(fd);
         return -1;
     }
diff --git a/src/daemon/executor/container_cb/execution_network.c b/src/daemon/executor/container_cb/execution_network.c
index 597c3d6e..6ea40611 100644
--- a/src/daemon/executor/container_cb/execution_network.c
+++ b/src/daemon/executor/container_cb/execution_network.c
@@ -67,8 +67,8 @@ static int write_hostname_to_file(const char *rootfs, const char *hostname)
 
     ret = util_write_file(file_path, hostname, strlen(hostname), NETWORK_MOUNT_FILE_MODE);
     if (ret) {
-        SYSERROR("Failed to write %s", file_path);
-        isulad_set_error_message("Failed to write %s: %s", file_path, strerror(errno));
+        SYSERROR("Failed to write %s.", file_path);
+        isulad_set_error_message("Failed to write %s.", file_path);
         goto out;
     }
 
@@ -96,8 +96,8 @@ static int fopen_network(FILE **fp, char **file_path, const char *rootfs, const
 
     *fp = util_fopen(*file_path, "a+");
     if (*fp == NULL) {
-        SYSERROR("Failed to open %s", *file_path);
-        isulad_set_error_message("Failed to open %s: %s", *file_path, strerror(errno));
+        SYSERROR("Failed to open %s.", *file_path);
+        isulad_set_error_message("Failed to open %s.", *file_path);
         return -1;
     }
     return 0;
@@ -168,8 +168,8 @@ static int write_content_to_file(const char *file_path, const char *content)
     if (content != NULL) {
         ret = util_write_file(file_path, content, strlen(content), NETWORK_MOUNT_FILE_MODE);
         if (ret != 0) {
-            SYSERROR("Failed to write file %s", file_path);
-            isulad_set_error_message("Failed to write file %s: %s", file_path, strerror(errno));
+            SYSERROR("Failed to write file %s.", file_path);
+            isulad_set_error_message("Failed to write file %s.", file_path);
             return ret;
         }
     }
@@ -701,9 +701,8 @@ static int chown_network(const char *user_remap, const char *rootfs, const char
         goto out;
     }
     if (chown(file_path, host_uid, host_gid) != 0) {
-        SYSERROR("Failed to chown network file '%s' to %u:%u", filename, host_uid, host_gid);
-        isulad_set_error_message("Failed to chown network file '%s' to %u:%u: %s", filename, host_uid, host_gid,
-                                 strerror(errno));
+        SYSERROR("Failed to chown network file '%s' to %u:%u.", filename, host_uid, host_gid);
+        isulad_set_error_message("Failed to chown network file '%s' to %u:%u.", filename, host_uid, host_gid);
         ret = -1;
         goto out;
     }
diff --git a/src/daemon/executor/container_cb/execution_stream.c b/src/daemon/executor/container_cb/execution_stream.c
index 7e84cca3..aae9c234 100644
--- a/src/daemon/executor/container_cb/execution_stream.c
+++ b/src/daemon/executor/container_cb/execution_stream.c
@@ -536,7 +536,7 @@ static container_path_stat *do_container_stat_path(const char *rootpath, const c
     nret = lstat(resolvedpath, &st);
     if (nret < 0) {
         SYSERROR("lstat %s failed.", resolvedpath);
-        isulad_set_error_message("lstat %s: %s", resolvedpath, strerror(errno));
+        isulad_set_error_message("lstat %s failed.", resolvedpath);
         goto cleanup;
     }
 
@@ -922,7 +922,7 @@ static int copy_to_container_check_path_valid(const container_t *cont, const cha
     nret = lstat(resolvedpath, &st);
     if (nret < 0) {
         SYSERROR("lstat %s failed", resolvedpath);
-        isulad_set_error_message("lstat %s: %s", resolvedpath, strerror(errno));
+        isulad_set_error_message("lstat %s failed", resolvedpath);
         goto cleanup;
     }
 
diff --git a/src/daemon/modules/container/container_unix.c b/src/daemon/modules/container/container_unix.c
index f85e8237..4ca7c87e 100644
--- a/src/daemon/modules/container/container_unix.c
+++ b/src/daemon/modules/container/container_unix.c
@@ -480,7 +480,7 @@ static int save_json_config_file(const char *id, const char *rootpath, const cha
     nret = util_atomic_write_file(filename, json_data, strlen(json_data), CONFIG_FILE_MODE, false);
     if (nret != 0) {
         SYSERROR("Write file %s failed.", filename);
-        isulad_set_error_message("Write file '%s' failed: %s", filename, strerror(errno));
+        isulad_set_error_message("Write file '%s' failed.", filename);
         ret = -1;
     }
 
diff --git a/src/daemon/modules/image/external/ext_image.c b/src/daemon/modules/image/external/ext_image.c
index 598299ea..5b6b7298 100644
--- a/src/daemon/modules/image/external/ext_image.c
+++ b/src/daemon/modules/image/external/ext_image.c
@@ -65,8 +65,8 @@ int ext_prepare_rf(const im_prepare_request *request, char **real_rootfs)
                 return -1;
             }
             if (realpath(request->rootfs, real_path) == NULL) {
-                SYSERROR("Failed to clean rootfs path '%s'", request->rootfs);
-                isulad_set_error_message("Failed to clean rootfs path '%s': %s", request->rootfs, strerror(errno));
+                SYSERROR("Failed to clean rootfs path '%s'.", request->rootfs);
+                isulad_set_error_message("Failed to clean rootfs path '%s'.", request->rootfs);
                 return -1;
             }
             *real_rootfs = util_strdup_s(real_path);
diff --git a/src/daemon/modules/image/oci/oci_load.c b/src/daemon/modules/image/oci/oci_load.c
index 2a920c22..7dfc5cb6 100644
--- a/src/daemon/modules/image/oci/oci_load.c
+++ b/src/daemon/modules/image/oci/oci_load.c
@@ -1029,7 +1029,7 @@ static char *oci_load_path_create()
 
     if (mkdtemp(tmp_dir) == NULL) {
         SYSERROR("make temporary dir failed");
-        isulad_try_set_error_message("make temporary dir failed: %s", strerror(errno));
+        isulad_try_set_error_message("make temporary dir failed");
         ret = -1;
         goto out;
     }
diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
index e985cfc1..f61316d0 100644
--- a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
+++ b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
@@ -209,9 +209,8 @@ static int remove_container_rootpath(const char *id, const char *root_path)
     }
     ret = util_recursive_rmdir(cont_root_path, 0);
     if (ret != 0) {
-        const char *tmp_err = (errno != 0) ? strerror(errno) : "error";
         SYSERROR("Failed to delete container's root directory %s.", cont_root_path);
-        isulad_set_error_message("Failed to delete container's root directory %s: %s", cont_root_path, tmp_err);
+        isulad_set_error_message("Failed to delete container's root directory %s.", cont_root_path);
         ret = -1;
         goto out;
     }
diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c
index c776e53f..b2ef4644 100644
--- a/src/daemon/modules/service/service_container.c
+++ b/src/daemon/modules/service/service_container.c
@@ -586,7 +586,7 @@ static int valid_mount_point(container_config_v2_common_config_mount_points_elem
 
     if (lstat(mp->source, &st) != 0) {
         SYSERROR("lstat %s failed", mp->source);
-        isulad_set_error_message("lstat %s: %s", mp->source, strerror(errno));
+        isulad_set_error_message("lstat %s failed", mp->source);
         return -1;
     }
 
diff --git a/src/daemon/modules/spec/verify.c b/src/daemon/modules/spec/verify.c
index 5b6f298f..2f2d3925 100644
--- a/src/daemon/modules/spec/verify.c
+++ b/src/daemon/modules/spec/verify.c
@@ -1510,7 +1510,7 @@ static int verify_custom_mount(defs_mount **mounts, size_t len)
         if (!util_file_exists(iter->source) && util_mkdir_p(iter->source, mode)) {
 #endif
             SYSERROR("Failed to create directory '%s'", iter->source);
-            isulad_try_set_error_message("Failed to create directory '%s': %s", iter->source, strerror(errno));
+            isulad_try_set_error_message("Failed to create directory '%s'", iter->source);
             ret = -1;
             goto out;
         }
diff --git a/src/daemon/modules/volume/local.c b/src/daemon/modules/volume/local.c
index f14025e4..e128c942 100644
--- a/src/daemon/modules/volume/local.c
+++ b/src/daemon/modules/volume/local.c
@@ -556,15 +556,15 @@ static int remove_volume_dir(char *path)
     // remain untouched if we remove the data directory failed.
     ret = util_recursive_rmdir(path, 0);
     if (ret != 0) {
-        SYSERROR("failed to remove volume data dir %s", path);
-        isulad_try_set_error_message("failed to remove volume data dir %s: %s", path, strerror(errno));
+        SYSERROR("failed to remove volume data dir %s.", path);
+        isulad_try_set_error_message("failed to remove volume data dir %s.", path);
         goto out;
     }
 
     ret = util_recursive_rmdir(vol_dir, 0);
     if (ret != 0) {
-        SYSERROR("failed to remove volume dir %s", vol_dir);
-        isulad_try_set_error_message("failed to remove volume dir %s: %s", vol_dir, strerror(errno));
+        SYSERROR("failed to remove volume dir %s.", vol_dir);
+        isulad_try_set_error_message("failed to remove volume dir %s.", vol_dir);
         goto out;
     }
 
diff --git a/src/utils/tar/isulad_tar.c b/src/utils/tar/isulad_tar.c
index fa844919..bb82e477 100644
--- a/src/utils/tar/isulad_tar.c
+++ b/src/utils/tar/isulad_tar.c
@@ -115,7 +115,7 @@ static int resolve_host_source_path(const char *path, bool follow_link, char **r
     if (follow_link) {
         if (realpath(path, real_path) == NULL) {
             SYSERROR("Can not get real path of %s.", real_path);
-            format_errorf(err, "Can not get real path of %s: %s", real_path, strerror(errno));
+            format_errorf(err, "Can not get real path of %s.", real_path);
             return -1;
         }
         nret = get_rebase_name(path, real_path, resolved_path, rebase_name);
@@ -132,7 +132,7 @@ static int resolve_host_source_path(const char *path, bool follow_link, char **r
         }
         if (realpath(dirpath, real_path) == NULL) {
             SYSERROR("Can not get real path of %s.", dirpath);
-            format_errorf(err, "Can not get real path of %s: %s", dirpath, strerror(errno));
+            format_errorf(err, "Can not get real path of %s.", dirpath);
             goto cleanup;
         }
         nret = snprintf(resolved, sizeof(resolved), "%s/%s", real_path, basepath);
@@ -193,7 +193,7 @@ struct archive_copy_info *copy_info_source_path(const char *path, bool follow_li
     nret = lstat(resolved_path, &st);
     if (nret < 0) {
         SYSERROR("lstat %s failed", resolved_path);
-        format_errorf(err, "lstat %s: %s", resolved_path, strerror(errno));
+        format_errorf(err, "lstat %s failed", resolved_path);
         goto cleanup;
     }
 
@@ -226,8 +226,8 @@ static int copy_info_destination_path_ret(struct archive_copy_info *info, struct
 
         ret = (int)readlink(iter_path, target, PATH_MAX);
         if (ret < 0) {
-            SYSERROR("Failed to read link of %s", iter_path);
-            format_errorf(err, "Failed to read link of %s: %s", iter_path, strerror(errno));
+            SYSERROR("Failed to read link of %s.", iter_path);
+            format_errorf(err, "Failed to read link of %s.", iter_path);
             goto cleanup;
         }
         // is not absolutely path
@@ -259,8 +259,8 @@ static int copy_info_destination_path_ret(struct archive_copy_info *info, struct
     if (ret != 0) {
         char *dst_parent = NULL;
         if (errno != ENOENT) {
-            SYSERROR("Can not stat %s", iter_path);
-            format_errorf(err, "Can not stat %s: %s", iter_path, strerror(errno));
+            SYSERROR("Can not stat %s.", iter_path);
+            format_errorf(err, "Can not stat %s.", iter_path);
             goto cleanup;
         }
 
@@ -430,7 +430,7 @@ static int tar_resource_rebase(const char *path, const char *rebase, const char
 
     if (lstat(path, &st) < 0) {
         SYSERROR("lstat %s failed", path);
-        format_errorf(err, "lstat %s: %s", path, strerror(errno));
+        format_errorf(err, "lstat %s failed", path);
         return -1;
     }
     if (util_split_path_dir_entry(path, &srcdir, &srcbase) < 0) {
diff --git a/src/utils/tar/util_archive.c b/src/utils/tar/util_archive.c
index 89b075d3..4653bc98 100644
--- a/src/utils/tar/util_archive.c
+++ b/src/utils/tar/util_archive.c
@@ -254,8 +254,8 @@ static int do_safe_chroot(const char *dstdir)
     prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
 
     if (chroot(dstdir) != 0) {
-        SYSERROR("Failed to chroot to %s", dstdir);
-        fprintf(stderr, "Failed to chroot to %s: %s", dstdir, strerror(errno));
+        SYSERROR("Failed to chroot to %s.", dstdir);
+        fprintf(stderr, "Failed to chroot to %s.", dstdir);
         return -1;
     }
 
@@ -843,15 +843,15 @@ int archive_unpack(const struct io_read_wrapper *content, const char *dstdir, co
         }
 
         if (do_safe_chroot(safe_dir) != 0) {
-            SYSERROR("Failed to chroot to %s", safe_dir);
-            fprintf(stderr, "Failed to chroot to %s: %s", safe_dir, strerror(errno));
+            SYSERROR("Failed to chroot to %s.", safe_dir);
+            fprintf(stderr, "Failed to chroot to %s.", safe_dir);
             ret = -1;
             goto child_out;
         }
 
         if (chdir("/") != 0) {
             SYSERROR("Failed to chroot to /");
-            fprintf(stderr, "Failed to chroot to /: %s", strerror(errno));
+            fprintf(stderr, "Failed to chroot to /");
             ret = -1;
             goto child_out;
         }
@@ -1250,7 +1250,7 @@ int archive_chroot_tar(const char *path, const char *file, const char *root_dir,
         fd = open(file, TAR_DEFAULT_FLAG, TAR_DEFAULT_MODE);
         if (fd < 0) {
             SYSERROR("Failed to open file %s for export", file);
-            fprintf(stderr, "Failed to open file %s for export: %s\n", file, strerror(errno));
+            fprintf(stderr, "Failed to open file %s for export\n", file);
             ret = -1;
             goto child_out;
         }
-- 
2.40.1

